[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: find out if my parent is the last sibling
Hi Jan, > for the child it is easy to find out if it is the last in the row, > <xsl:if test="position()=last()">*</xsl:if> > but how can a child know this about it's parent? Depending on how you're doing the processing of the parents, you can use a variable as follows: <xsl:for-each select="parent"> <xsl:variable name="is-last" select="position() = last()" /> ... <xsl:for-each select="child"> ... <xsl:if test="$is-last"> parent has no following siblings </xsl:if> ... </xsl:for-each> </xsl:for-each> Or you can use the test: ../following-sibling::* which tests more literally whether the parent node has any following siblings (but is slightly less efficient than storing this information in a variable). I often find, though, that the best thing to do is to rearrange the code so that whatever you want to happen when the parent is the last sibling happens when the current node is the parent. In other words, to do something like: <xsl:for-each select="parent"> ... <xsl:for-each select="child"> ... </xsl:for-each> <xsl:if test="position() = last()">...</xsl:if> </xsl:for-each> If you showed us what you were actually trying to do then we could see if that was a more appropriate solution. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|