470,870 Members | 1,406 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

xsl:number newb question

Hi group!

Basic question about counting specific nodes in the range, here the
example:

XSL:

<xsl:stylesheet version="1.0">
<xsl:template match="/">

Red cars:
<xsl:for-each select="car">
<xsl:if test="color = 'red'">
<xsl:number select="position()"/>.
<xsl:value-of select="manufacturer"/> ( <xsl:value-of
select="model"/> )
</xsl:if>
</xsl:for-each>

Blue cars:
<xsl:for-each select="car">
<xsl:if test="color = 'blue'">
<xsl:number select="position()"/>.
<xsl:value-of select="manufacturer"/> ( <xsl:value-of
select="model"/> )
</xsl:if>
</xsl:for-each>

</xsl:template>
</xsl:stylesheet>

I want to get XSLT result that will look like:
Red cars:
1. Ford (67)
2. AM (78)

Blue cars:
1. Fiat (92)
2. Toyota (06)
3. Ford (05)

But instead of it I get numbering of actualy nodes positions in
original XML.

Feb 20 '06 #1
5 1184
I don't quite get what you're asking here, could you elaborate? What
number do you want if its not the node number?

Feb 20 '06 #2


Guiding5 wrote:

<xsl:for-each select="car">
<xsl:if test="color = 'red'">
<xsl:for-each select="car[color = 'red']">
I want to get XSLT result that will look like:
Red cars:
1. Ford (67)
2. AM (78)


should do that.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 20 '06 #3
Well, with given stylesheet I will get something like this (instead of
wanted):

1. Ford (67)
4. AM (78)

Blue cars:
2. Fiat (92)
3. Toyota (06)
5. Ford (05)

Counting will be according the real positions of elements in input XML.
The question is, how do I count elements in resulting XSLT ? How do I
get counting related to if condition ?

Feb 20 '06 #4
This actually did the job!

Thanks alot, it works, even if I still dont understand why :)

Feb 20 '06 #5


Guiding5 wrote:
it works, even if I still dont understand why :)


position() gives the position in the current node list, you had all car
elements in that list while my approach made sure the current node list
had only the red (or the blue) cars when position() is evaluated.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 20 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by johkar | last post: by
4 posts views Thread by Jyrki Keisala | last post: by
9 posts views Thread by Tom | last post: by
3 posts views Thread by Andy Fish | last post: by
reply views Thread by Patrick.O.Ige | last post: by
reply views Thread by Jean-François Michaud | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.