470,826 Members | 1,809 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,826 developers. It's quick & easy.

need help: position and count

with an xpath expr: step1/step2[pred]
I'm trying to get the position() of step2, using the qualifying
predicate.
I've seen some suggestions, of ways to do this, using count() instead,
but I'm not sure count would work.

Here's an excerpt from a 2003 post reply by Novatchev
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Also, the XPath position() function is defined on the current
*node-list*,
not node-set. This means that position() can be used:
1) in a relation in predicates within an XPath expression to select
nodes
whose position in the current node-list satisfies this relation,
or
2) in the body of xsl:for-each or of xsl:template to return the
position of
the current node in the current node-list.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node-list or node-set ?? whats the difference ?

I think I've seen an example of (2) somewhere, but another one would
help.

Apr 12 '06 #1
3 1492


awebguynow wrote:

2) in the body of xsl:for-each or of xsl:template to return the
position of
the current node in the current node-list. I think I've seen an example of (2) somewhere, but another one would
help.


<xsl:template match="element-name">
<xsl:value-of select="position()" />
</xsl:template>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Apr 12 '06 #2
my version looked like:
<xsl:for-each select="step1/step2">
<xsl:if test="child_node=$my_param">
<xsl:value-of select="position()"/><br/>
</xsl:if>
</xsl:for-each>

Using this I was able to output the position, but I was unable to set a
variable based on position()
I tried this way (substitute this line as the inner line above)
<xsl:variable name="pos" select="position()"/>

however $pos was not recognized as a variable, outside the for-each
loop.
I realize variable are final and either have global scope or template
scope, based on where they are declared. (or at least that was my
understanding).

Apr 12 '06 #3
> I realize variable are final and either have global scope or template
scope


Varables in XSLT are all local; they do not persist outside the element
containing the <xsl:variable>. You can pass values forward and down, but
not up except as results of the XSLT expression.

Try something like

<xsl:variable name="pos">
<xsl:for-each select="step1/step2">
<xsl:if test="child_node=$my_param">
<xsl:value-of select="position()"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>

If you're sure there's only one child node which matches the test, this
will return its position. If there are several, it will return a
concatenation of the positions; you could then parse them apart (but
would probably want to add a delimiter between them to make doing so
easier).


--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Apr 14 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mike | last post: by
2 posts views Thread by Alexander | last post: by
1 post views Thread by sommarlov | last post: by
1 post views Thread by satan | last post: by
3 posts views Thread by Perry Langla | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.