473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1264
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: johkar | last post by:
My XML and XSL is below. Also below is a textual representation of what I want to get out of the XML with XSL. For each Extension node in XML, I am only concerned with those nodes with...
4
by: Jyrki Keisala | last post by:
I have an XML file: <document> <record> <element1>Text</element1> <element2>More text</element2> <element3>Even more text</element3> <element4>Some text <link><title>Google</title><url>...
9
by: Tom | last post by:
Hey all, I've been planning to get myself started with DocBook for quite some time now, so when I unexpectedly encountered a task for which DocBook might actually be very useful, I thought I'd...
1
by: 5tein | last post by:
I mean, with XSL functions such as SELECT can I only refer to XML element values or can I somehow also refer to XML attribute values? Is there any way to refer to XML content based on attribute...
3
by: Andy Fish | last post by:
In my XSLT stylesheet, if I call <xsl:number level="any" count="sdfsjdfjsdfksndfn"/> where there are no preceeding nodes called "sdfsjdfjsdfksndfn" I would expect it to return 0. However, on...
3
by: b0yce | last post by:
Hi Group, I think I have found a problem with the <xsl:element> when being transformed by the .NET xmlTransform class. When using XmlSpy for development and debugging, the <xsl:number>...
0
by: Patrick.O.Ige | last post by:
I have a xml file and i want to format it using XSL I needed to do a distinct which is ok on the first node "Code" But when it gets to the "programDescription" node it prints out values for both...
0
by: Jean-François Michaud | last post by:
Hello all, I'm looking into putting together an alternate page numbering on a figure element that we have to deal with. Each figure has its own page sequence through the use of an...
14
by: ajfish | last post by:
Hi, I am trying to allocate a unique ID to every instance of tag 'foo' in a large XML document. currently I'm doing this: <xsl:variable name="UniqueId"> <xsl:number count="foo" level="any"/>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.