javajoemorgan Posted January 24, 2008 Share Posted January 24, 2008 How do I know if an element is the last of its kind in the entire document...For example, I think this gets the last HEADING element in the doc//HEADING[last()] So, If I'm within the HEADING template, how do I basically write:<xsl:if test="self = //HEADING[last()]">.......It seems like //HEADING[last()] is always returning the last heading relative to it's level.----------------Follow-Up: OK... through experimentation, I've proved that //HEADING[last()] is always returing the last element on the first level rather than anywhere in the document. How does one get the last element, regardless of it's level of nesting. <X> <B> <A>1 <A>2</A> </A> </B> <C> <D> <A>3</A> </D> </C></X> I would suspect that //A[last()] would return A3, but it returns A1.... Why? and how do you generically get to A3. Link to comment Share on other sites More sharing options...
aalbetski Posted January 24, 2008 Share Posted January 24, 2008 I would create a node set variable and then use the last()<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" > <xsl:template match="*"> <xsl:variable name="AllAs" select="//A" /> <xsl:value-of select="$AllAs[last()]"/> </xsl:template></xsl:stylesheet> Link to comment Share on other sites More sharing options...
javajoemorgan Posted January 25, 2008 Author Share Posted January 25, 2008 I would create a node set variable and then use the last()<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" > <xsl:template match="*"> <xsl:variable name="AllAs" select="//A" /> <xsl:value-of select="$AllAs[last()]"/> </xsl:template></xsl:stylesheet>Oh yeah!... That makes sense... Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.