xsl-list
[Top] [All Lists]

RE: RE: Article Paging With

2003-01-16 14:48:56
*** 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[(_at_)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[(_at_)display='contents' and position() != 
last()]">
 <xsl:variable name="next-article-id">
   <xsl:value-of select="following-sibling::article[(_at_)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[(_at_)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[(_at_)display='contents' and position() != 1]">
 <xsl:variable name="next-article-id">
   <xsl:value-of select="preceding-sibling::article[(_at_)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[(_at_)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(_at_)onebox(_dot_)com - email


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



<Prev in Thread] Current Thread [Next in Thread>
  • RE: RE: Article Paging With, cknell <=