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

RE: navigation, TEI

Subject: RE: [xsl] navigation, TEI
From: <Jarno.Elovirta@xxxxxxxxx>
Date: Wed, 23 Jun 2004 09:22:01 +0300
stylesheet set navigation
Hi,

> I'm working on extending the TEI xsl stylesheet set with a more
> complex 'prev-next' navigation bar. For the linking i need two
> parameters: the text of the link, and the id of the link.
> I use a template to get the appropriate node:
> 
> <xsl:template name="getPrev">
>   <xsl:variable name="nodeSet">
>     <xsl:text>self::div0 | self::div1 | self::div2 | 
> self::div3 | self::div4</xsl:text>
>   </xsl:variable>

Here you're binding $nodeSet to a Result Tree Fragment and…
 
>   <xsl:choose>
>     <xsl:when test="(preceding-sibling::*[$nodeSet]/head)[last()]">

… here if will always return true. Either copy/paste the $nodeSet text into every place where it's used or use an entity instead of a variable.

>       <xsl:copy-of select="preceding::*[$nodeSet]/head[last()]" />
>     </xsl:when>
>     <xsl:when test="(ancestor::*[$nodeSet]/head)[last()]">
>       <xsl:copy-of select="ancestor::*[$nodeSet]/head[last()]" />

Note here that the test pattern and the copy expression do not select/match the same nodes, just like in the previous when block if the axes were the same.

>     </xsl:when>
>     <xsl:otherwise></xsl:otherwise>
>   </xsl:choose>
> </xsl:template>
> 
> and i call this with:
> <xsl:variable name="previous">
>   <xsl:call-template name="getPrev" />
> </xsl:variable>

And again, you're binding $previous to a RTF.

> but as i would like to get the id of the node the following 
> code doesn't work:
> 
>   <xsl:variable name="previousID">
>     <xsl:value-of select="generate-id( $previous )" />
>   </xsl:variable>
> 
> with the xsl processor saying: 'generate-id() : invalid arg 
> expecting a node-set'
> So i have to write another template (getPrevID) with the only 
> difference of the selection:
>   'select="generate-id( ... )"'
> 
> and the xpath expression
>   (preceding-sibling::*[$nodeSet]/head)[last()]
> is the same than this:
>   (preceding-sibling::*/head)[last()]
> the $nodeSet variable doesn't work at this situation.

How about

  <xsl:template name="getPrevID">
    <xsl:choose>
      <!--here you don't need to test for the last, because it will be true even if you have just one div# head -->
      <xsl:when test="preceding-sibling::*[self::div0 | self::div1 | self::div2 | self::div3 | self::div4]/head">
        <xsl:value-of select="generate-id(preceding::*[self::div0 | self::div1 | self::div2 | self::div3 | self::div4]/head[last()])" />
      </xsl:when>
      <xsl:when test="ancestor::*[self::div0 | self::div1 | self::div2 | self::div3 | self::div4]/head">
        <xsl:value-of select="generate-id(ancestor::*[self::div0 | self::div1 | self::div2 | self::div3 | self::div4]/head[last()])" />
      </xsl:when>
    </xsl:choose>
  </xsl:template>

Cheers,

Jarno - Cenobita: Slaves
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.