Subject: Re: position() From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Thu, 10 Aug 2000 22:01:07 +0100 |
Steve, >I guess I don't understand the "position" function. I am trying to see >if the node I'm processing is the last one, but it never works: > ><xsl:template match="a/b"> ><xsl:if test="position(..)=last(../../a)"> ></xsl:if> >xsl:apply-templates/> </xsl:template> position() and last() never take any arguments. position() gives you the position of the current node in the current node list. last() gives you the number of nodes in the current node list. Thus, "position() = last()" returns true if the current node is the last node in the current node list. The current node is the one you're currently processing. In your case, it's a 'b' element that is a child of an 'a' element. The current node list is the list of nodes that are being processed under the same instruction. The 'a/b'-matching template is being applied because somewhere up the line there's been an xsl:apply-templates instruction that has selected some 'b' elements to be processed. You need to look at that xsl:apply-templates instruction to see what the current node list is. If there isn't an explicit xsl:apply-templates instruction that would select the 'b' node, then it will be in a node list made up of itself and its siblings. This is because the built-in template applies templates to all the children of a particular node. The most likely case is that the 'b' element is being processed along with all its siblings. So, if you do: <xsl:template match="a/b"> <xsl:if test="position() = last()"> </xsl:if> </xsl:template> then the non-breaking spaces will only be added when the 'b' element is the last child of its parent (the 'a' element). If the judgement about whether the 'b' element is "last" is more complex than this (e.g. the last 'b' element in the document), then you might need something more complicated. Let me know. I hope that helps, Jeni Dr Jeni Tennison Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@xxxxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
position(), Steve Carton | Thread | Re: position(), John Robert Gardner |
RE: Possible to create HDML?, Joshua Allen | Date | RE: How to make the user selecting , Chris Bayes |
Month |