473,386 Members | 1,815 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,386 software developers and data experts.

loop in xslt

Hello,
I am new to xslt and try to have an argument that for each iteration
of the "FOR-EACH" will grow in one:

<xsl:for-each select="//AssetCode">
<node id="_1">
<xsl:attribute name="text">
<xsl:value-of select="."/>
</xsl:attribute>
</node>
I want id to be in the next iteration _2 and _3 in the next one
etc....

any ideas of how to do it?
Jul 20 '05 #1
3 4921
eb*******@mindspring.com (Eyal) wrote in message news:<ba**************************@posting.google. com>...
Hello,
I am new to xslt and try to have an argument that for each iteration
of the "FOR-EACH" will grow in one:

<xsl:for-each select="//AssetCode">
<node id="_1">
<xsl:attribute name="text">
<xsl:value-of select="."/>
</xsl:attribute>
</node>
I want id to be in the next iteration _2 and _3 in the next one
etc....

any ideas of how to do it?


I learned a lot from this article.

http://www.xml.com/pub/a/2001/08/01/gettingloopy.html
Jul 20 '05 #2
eb*******@mindspring.com (Eyal) writes:
Hello,
I am new to xslt and try to have an argument that for each iteration
of the "FOR-EACH" will grow in one:

<xsl:for-each select="//AssetCode">
<node id="_1">
<xsl:attribute name="text">
<xsl:value-of select="."/>
</xsl:attribute>
</node>
I want id to be in the next iteration _2 and _3 in the next one
etc....

any ideas of how to do it?
Use the XPath position() function.

These data

<test>
<AssetCode>abc</AssetCode>
<AssetCode>def</AssetCode>
<AssetCode>ghi</AssetCode>
<AssetCode>jkl</AssetCode>
</test>

with a very slight modification to your stylesheet:

<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"


<xsl:template match="/">
<xsl:for-each select="//AssetCode">
<node id="_{position()}">
<xsl:attribute name="text">
<xsl:value-of select="."/>
</xsl:attribute>
</node>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
Gives this output

<?xml version="1.0"?>
<node id="_1" text="abc"/><node id="_2" text="def"/>
<node id="_3" text="ghi"/><node id="_4" text="jkl"/>
Ben

--
Ben Edgington
Mail to the address above is discarded.
Mail to ben at that address might be read.
www.edginet.org
Jul 20 '05 #3
Thanks Ben, It works great.

Ben Edgington <us****@edginet.org> wrote in message news:<87************@edginet.org>...
eb*******@mindspring.com (Eyal) writes:
Hello,
I am new to xslt and try to have an argument that for each iteration
of the "FOR-EACH" will grow in one:

<xsl:for-each select="//AssetCode">
<node id="_1">
<xsl:attribute name="text">
<xsl:value-of select="."/>
</xsl:attribute>
</node>
I want id to be in the next iteration _2 and _3 in the next one
etc....

any ideas of how to do it?


Use the XPath position() function.

These data

<test>
<AssetCode>abc</AssetCode>
<AssetCode>def</AssetCode>
<AssetCode>ghi</AssetCode>
<AssetCode>jkl</AssetCode>
</test>

with a very slight modification to your stylesheet:

<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"


<xsl:template match="/">
<xsl:for-each select="//AssetCode">
<node id="_{position()}">
<xsl:attribute name="text">
<xsl:value-of select="."/>
</xsl:attribute>
</node>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
Gives this output

<?xml version="1.0"?>
<node id="_1" text="abc"/><node id="_2" text="def"/>
<node id="_3" text="ghi"/><node id="_4" text="jkl"/>
Ben

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ted | last post by:
Was wondering if XSLT alone is appropriate for the following situation. From XML, I'm creating a small website (around 50 pages) with pages that link to each other through a nav menu and a...
6
by: dSchwartz | last post by:
What I think I'm looking for is a way (in XSL stylesheet) to get the contents of a directory. How can this be accomplished? more detailed: /root index.aspx xsl_style.xsl /xml...
1
by: Mohit | last post by:
Hi Friends I have to call 1 of the 2 child XSLT files from the Main XSLT file based on some criteria. I want one child XSLT file will be executed by version 1 of XSLT processor and the other by...
1
by: chris yoker via DotNetMonster.com | last post by:
hiya, I add new nodes to an xmlDoc. I want to add "innerText" to every newly-created node. current XML file <code> <rows> <row> <PRODUCT-TYPE>bike</PRODUCT-TYPE>...
3
by: Teksure | last post by:
Hi group, searching in the Internet I found two products for XML which incorporate a very robust debugger for XSL/XSLT, I would like you to see these products and then, give me your opinion about...
4
by: Iain | last post by:
Hi all, I am try to split the some data out of a nested xml file and get all the data in one new xml file. I have two XSLT files one takes the personal information and one takes the data out of...
1
by: Sergey Dubinets | last post by:
In effort to prioritize our goals we composed the list of random features each of them may add value to set of XSLT tools offered from Microsoft. 1. XSLTc (Compiler for XSLT...
6
by: andyalean1 | last post by:
Hello, I am trying to match an Id number that is shared across 2 xml files.I seem to be do the right thing bu it won`t display a match.Can you please help me find my error. I have a problem matching...
1
by: yousuf20022002 | last post by:
Hi Guys, I am struck with something in XML.Here it is what I am doing ... xml format is like <root> <user1> <details> <firstname>asdf </firstname> <lastname>mhmm ...
2
by: anii | last post by:
Hi I'm a bit new to XML, and I was wondering if anyone could help me with my problem. I have one XML document (readings.xml) being linked to an XSLT document via JavaScript DOM, and am linking the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.