468,267 Members | 1,847 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

position()-function with hereogenious siblings

Hi!

I have the following xml structure:

<DBCommands>
<Customer/>
<Contract/> <--- I am here
<Contract/>
</DBCommands>
my stylesheet

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

This is a constructed example, maybe the structure is stupid but it is
good to explain my issue.

When I am at the first "Contract" Element (marked above), the
position()-function will give me an "2", because it is the second
element underneath "DBCommands".

What I want: I want to have the position of the element filtered by
"Contract"; the processor should only count the "Contract"-elements,
not the "Customer"-elements.

So my desired result would be "1", because I am at the first "Contract"
element.

Does anyone know how to manage this?

Thanks and best regards,

Bernd

Mar 31 '06 #1
1 1125


bl*******@gmx.net wrote:

I have the following xml structure:

<DBCommands>
<Customer/>
<Contract/> <--- I am here
<Contract/>
</DBCommands>
my stylesheet

<xsl:template match="Contract">
<xsl:value-of select="position()">
</xsl:template> When I am at the first "Contract" Element (marked above), the
position()-function will give me an "2", because it is the second
element underneath "DBCommands".


That depends on how the template is called, if you have e.g.
<xsl:template match="DBCommands">
<xsl:apply-templates select="Contract" />
then position() above will yield 1. So position() results depend on the
current context and that is not determined by your <xsl:template
match="Contract"> but elsewhere.

If you don't want to rely on the position function then you can of
course do e.g.
count(preceding-sibling::Contract) + 1
--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 31 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Zenobia | last post: by
4 posts views Thread by Peter Fjelsten | last post: by
3 posts views Thread by Markus Ernst | last post: by
3 posts views Thread by akunamatata | last post: by
4 posts views Thread by Guy | last post: by
3 posts views Thread by moondaddy | last post: by
6 posts views Thread by Gérard Talbot | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.