Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old February 20th, 2006, 03:45 PM
Guiding5
Guest
 
Posts: n/a
Default 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.

  #2  
Old February 20th, 2006, 04:45 PM
steve_marjoribanks
Guest
 
Posts: n/a
Default Re: xsl:number newb question

I don't quite get what you're asking here, could you elaborate? What
number do you want if its not the node number?

  #3  
Old February 20th, 2006, 04:45 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: xsl:number newb question



Guiding5 wrote:
[color=blue]
>
> <xsl:for-each select="car">
> <xsl:if test="color = 'red'">[/color]

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

should do that.

--

Martin Honnen
http://JavaScript.FAQTs.com/
  #4  
Old February 20th, 2006, 04:55 PM
Guiding5
Guest
 
Posts: n/a
Default Re: xsl:number newb question

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 ?

  #5  
Old February 20th, 2006, 05:35 PM
Guiding5
Guest
 
Posts: n/a
Default Re: xsl:number newb question

This actually did the job!

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

  #6  
Old February 20th, 2006, 05:45 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: xsl:number newb question



Guiding5 wrote:
[color=blue]
> it works, even if I still dont understand why :)[/color]

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/
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles