[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Stumped on XPath

Subject: Re: Stumped on XPath
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 7 Feb 2006 22:04:20 GMT
Re:  Stumped on XPath
The trick with doing cross references in XSLT is always generate the
reference text _at the referenced node_ not on the referencing node.
then you can easily get the same number in the reference and in the
referenced heading. (Often by just calling a named template or special
mode that just does the numbering.

So at the referencing element, first follow the link, then generate the
number:

<xsl:stylesheet version="1.0"
              xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:key name="r" match="refnote" use="@id"/>

<xsl:template match="doc">
<html>
<head/>
<body>
 <xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="sentence">
  <p><xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="clause">
 <p class="clause"><xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="strong">
<strong><xsl:apply-templates/></strong>
</xsl:template>
<xsl:template match="appendix"/>
<xsl:template match="id">
<xsl:for-each select="key('r',@ref)">
 <xsl:text> (see Appendix </xsl:text>
 <xsl:number format="A"/>
 <xsl:text>) </xsl:text>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>



$ saxon refid.xml refid.xsl
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html;
charset=utf-8">
   </head>
   <body>


      <p>This is a sentence with a reference (see Appendix A)  as an
         inline element
      </p>

      <p class="clause">This is a clause with inline elements <strong>
            and</strong> a reference  (see Appendix B)
      </p>




   </body>
</html>

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.