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

Re: Determining last node

Subject: Re: Determining last node
From: "Larry Garfield" <lgarfiel@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 14 Aug 2001 10:07:04 -0500
xsl select last node
> -------- 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


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.