473,399 Members | 2,146 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,399 software developers and data experts.

XSL: Looping over non xml set

Hello,

I want to create m elements in this form:

<element index="n"/>

Where n = 1 2 .. m

Can is do this with an xsl:for loop??
And if so how

For example for m = 4

<xsl:variable name="m" select="4"/>
<xsl:for-each select="1 to m">
<element index="{position()}"/>
</foreach>

Output:

<element index="1"/>
<element index="2"/>
<element index="3"/>
<element index="4"/>

Is this possible with xslt 1.0 ?
Jul 20 '05 #1
3 11533
> Hello,

I want to create m elements in this form:

<element index="n"/>

Where n = 1 2 .. m

Can is do this with an xsl:for loop??
And if so how

For example for m = 4

<xsl:variable name="m" select="4"/>
<xsl:for-each select="1 to m">
<element index="{position()}"/>
</foreach>

Output:

<element index="1"/>
<element index="2"/>
<element index="3"/>
<element index="4"/>

Is this possible with xslt 1.0 ?

That's only possible in version 2.0
In XSLT 1.0, you must use a named attribute approach:

<xsl:call-template name="loop">
<xsl:with-param name="count">4</xsl:with-param>
</xsl:call-template>

<xsl:template name="loop">
<xsl:param name="count"/>
<xsl:param name="iteration">1</xsl:param>
<element index="{$iteration}"/>

<xsl:if test="$iteration &lt; $count">
<xsl:call-template name="loop">
<xsl:with-param name="count" select="$count"/>
<xsl:with-param name="iteration" select="$iteration +1"/>
</xsl:call-template>
</xsl:if>

</xsl:template>

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #2
Joris Gillis wrote:
Hello,

I want to create m elements in this form:

<element index="n"/>

Where n = 1 2 .. m

Can is do this with an xsl:for loop??
And if so how

For example for m = 4

<xsl:variable name="m" select="4"/>
<xsl:for-each select="1 to m">
<element index="{position()}"/>
</foreach>

Output:

<element index="1"/>
<element index="2"/>
<element index="3"/>
<element index="4"/>

Is this possible with xslt 1.0 ?


That's only possible in version 2.0
In XSLT 1.0, you must use a named attribute approach:

<xsl:call-template name="loop">
<xsl:with-param name="count">4</xsl:with-param>
</xsl:call-template>

<xsl:template name="loop">
<xsl:param name="count"/>
<xsl:param name="iteration">1</xsl:param>
<element index="{$iteration}"/>

<xsl:if test="$iteration &lt; $count">
<xsl:call-template name="loop">
<xsl:with-param name="count" select="$count"/>
<xsl:with-param name="iteration" select="$iteration +1"/>
</xsl:call-template>
</xsl:if>

</xsl:template>

regards,


that's a smart solution!
Jul 20 '05 #3

"Joris Gillis" <ro**@pandora.be> writes:
Hello,

I want to create m elements in this form:

<element index="n"/>

Where n = 1 2 .. m

Can is do this with an xsl:for loop??
And if so how

For example for m = 4

<xsl:variable name="m" select="4"/>
<xsl:for-each select="1 to m">
<element index="{position()}"/>
</foreach>

Output:

<element index="1"/>
<element index="2"/>
<element index="3"/>
<element index="4"/>

Is this possible with xslt 1.0 ?

That's only possible in version 2.0
In XSLT 1.0, you must use a named attribute approach:


Or so long as you know your soource document has enough nodes,

<xsl:for-each select="(//node())[position() &lt;=$m]">
<element index="{position()}"/>
</foreach>

David
Jul 20 '05 #4

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

Similar topics

2
by: FLEB | last post by:
Okay, so I've got this XML: <qa> <questionset> <question name="yourname">What is your name?</question> <question name="yourquest">What is your quest?</question> <question name="favcolor"> What...
0
by: Jimmy | last post by:
Hi, I have a (multi-tier) XML document and a XSL transform file (that is meant to transform the XML into a flat structure so I can insert the data into a database table). I have reached a...
1
by: Luke Dalessandro | last post by:
I have an application where there is a primary XML data file. I'll use the following as an example: <data> <item id="a"> <name>A</name> <price>$10</price> </item> <item id="b">...
8
by: bearclaws | last post by:
I am looping through a list of categories and want to display the list horizontally (instead of vertically). I want to create a single row with 4 list items in each cell of the row. I thought...
11
by: Rolf Barbakken | last post by:
I have an xml with records like this one: <a:response> <a:href>http://server/public/sol/comp/1049306.eml</a:href> <a:propstat> <a:status>HTTP/1.1 200 OK</a:status> <a:prop>...
4
by: freefly_xml | last post by:
I want to test to see if I am on the last page of a document. In this example it is an invoice. I want to print a different table in REGION AFTER when I am on the last page. I have tried many...
5
by: the_jos | last post by:
Dear reader, I am trying some things with xml/xsl and cannot find a solution for what I would like to do. I have 2 base items with name and price and two that are composed of base two (given...
2
by: NISHIL | last post by:
If have an Input Xml like <Rootnode1> <Field1>1</Field1> <Field2>2</Field2> <Field3>3</Field3> <Field4>4</Field4> </Rootnode1> I want to use XSL tranformatioms. In tht Transformation I want...
0
by: zamba | last post by:
hi im new with xsl and i have to process a xsl with a lot of xml (about 50.000) the transform is slow ..and i want to optimize my xsl . here is the example so if anybody could give some advices to...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.