472,351 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,351 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 11495
> 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...
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...
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>...
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...
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>...
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...
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...
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...
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...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.