This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Determining last node
- To: "XSL List" <xsl-list at lists dot mulberrytech dot com>
- Subject: Re: [xsl] Determining last node
- From: "Larry Garfield" <lgarfiel at students dot depaul dot edu>
- Date: Tue, 14 Aug 2001 10:07:04 -0500
- Reply-To: xsl-list at lists dot mulberrytech dot com
> -------- Original Message --------
> Larry Garfield wrote:
> > What xpath statement do I need to use to determine
> > if the current chapter element or sect1 element
> > is the "last of its kind"?
> >
> Context independent solutions (for chapter, substitute
> sect1 as appropriate)
> last chapter in document: test="not(following::chapter)"
> last chapter in parent element:
> test="not(following-sibling::chapter)"
> last chapter in subtree starting at parent element
> test="not(following-sibling::*[descendant-or-self::chapter)"
> I think you want the first.
>
> HTH
> J.Pietschmann
I tried using all three method, in both the chapter and sect1 sections. The
result is that when clause catches EVERY element. I am guessing it is
because there is a for-each statement above it, albeit on the other side of
a template, which is causing there to never be a following::node().
Specifically, it looks like (apologies if this wraps horribly):
...
<xsl:for-each select="book/chapter">
<xsl:call-template name="desktop-control"/>
</xsl:for-each>
...
<xsl:template match="chapter" name="desktop-control">
<xsl:variable name="chNum" select="position()"/>
Creating Desktop Chapter <xsl:value-of select="$chNum"/>
<xsl:variable name="chFileName">
<xsl:value-of select="$desktopOut"/>/chap<xsl:value-of
select="$chNum"/>.html</xsl:variable>
<redirect:write select="$chFileName">
<xsl:apply-templates select="$chapterTemplate/*">
<xsl:with-param name="chapter" select="."/>
<xsl:with-param name="chNum" select="$chNum"/>
<xsl:with-param name="tree" select="chapter"/>
</xsl:apply-templates>
</redirect:write>
</xsl:template>
<xsl:template match="call:insert[@id='NavbarDesktop']"> <!-- this is some
tag within the chain -->
<xsl:param name="chapter"/>
<xsl:param name="chNum"/>
<xsl:choose>
<xsl:when test="$chNum=1">[ <a href="index.html">Table of Contents</a> |
<a>
<xsl:attribute name="href">chap<xsl:value-of select="$chNum
+1"/>.html</xsl:attribute>
<xsl:value-of select="$source/book/chapter[position()=$chNum
+1]/title"/>
</a> ]</xsl:when>
<xsl:when test="not(following::chapter)">[ <a>
<xsl:attribute name="href">chap<xsl:value-of
select="$chNum -1"/>.html</xsl:attribute>
<xsl:value-of
select="$source/book/chapter[position()=$chNum -1]/title"/>
</a> | <a href="index.html">Table of Contents</a> ] </xsl:when>
<xsl:otherwise>[ <a>
<xsl:attribute name="href">chap<xsl:value-of
select="$chNum -1"/>.html</xsl:attribute>
<xsl:value-of
select="$source/book/chapter[position()=$chNum -1]/title"/>
</a> | <a href="index.html">Table of Contents</a> | <a>
<xsl:attribute name="href">chap<xsl:value-of select="$chNum
+1"/>.html</xsl:attribute>
<xsl:value-of select="$source/book/chapter[position()=$chNum
+1]/title"/>
</a> ] </xsl:otherwise>
</xsl:choose>
</xsl:template>
Am I correct in saying that the problem is the for-each? If so, what is the
recommended way to either circumvent it or use some other method that does
not chop up the tree?
--Larry Garfield
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list