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

RE: RE: Article Paging With

Subject: RE: RE: Article Paging With
From: cknell@xxxxxxxxxx
Date: Thu, 16 Jan 2003 16:48:56 -0500
asp paging
> *** Comments by KUBS, BENJAMIN    Thu Jan 16, 2003 -- 02:37:25 PM
> Your solution to my problem of finding the next article works 
> perfectly. I tried to implement the preceding-sibling XSLT command > to get the previous article in the same method and it always 
> returns the first node results (i.e. the first article). I read 
> that these axes return node sets which works for following because > the first node set in the results is the node I want. But for 
> preceding I need to get the last nodeset. I am having a difficult 
> time with that... I tried:
> 
> preceding-sibling::article[@display='contents' and position() = last()]
> 
> but that did not seem to work. Do you have the solution or should I > post back to the group?
> 
> Thanks for your help!
> 
> Ben

You should always reply to the list so that others who might be interested may follow the thread. 

That being said, I have an answer for you, but first a confession. The solution I sent to you works, but it was a fluke. The correct form is posted below, and beyond that, a solution for the new problem. Note that the postion predicate test should be moved from after the "/@id[1]" and "/title[1]" to the left of the slash "[1]/@id" and "[1]/title".

<xsl:template match="article[@display='contents' and position() != last()]">
 <xsl:variable name="next-article-id">
   <xsl:value-of select="following-sibling::article[@display = 'contents'][1]/@id" />
 </xsl:variable>
   <span style="width: 43%; float: right; text-align:right;">
     <a class="BottomNav" href="/cattails/cat/default.asp?artID={$next-article-id}">
       <img src="/cattails/images/next.gif" align="right" border="0" vspace="12" hspace="5" />
       <strong>Next Article</strong><br />
       <xsl:value-of select="following-sibling::article[@display = 'contents'][1]/title" />
     </a>
   </span>
</xsl:template>

I discovered my error when I was solving your second problem. Here is the solution for that one.:

<xsl:template match="article[@display='contents' and position() != 1]">
 <xsl:variable name="next-article-id">
   <xsl:value-of select="preceding-sibling::article[@display = 'contents'][1]/@id" />
 </xsl:variable>
   <span style="width: 43%; float: right; text-align:right;">
     <a class="BottomNav" href="/cattails/cat/default.asp?artID={$next-article-id}">
       <img src="/cattails/images/next.gif" align="right" border="0" vspace="12" hspace="5" />
       <strong>Next Article</strong><br />
       <xsl:value-of select="preceding-sibling::article[@display = 'contents'][1]/title" />
     </a>
   </span>
</xsl:template>

The handy thing about the preceding-sibling axis is that it gives you the nodes in "reverse document order", meaning that the first node in the list is the immediate predecessor to the context node.

Also note that I changed the XPath here to exclude the first article node as it has no preceding sibling and therefor would produce an invalid link anologous to the last article node in the former template.
-- 
Charles Knell
cknell@xxxxxxxxxx - email


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.