Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loops in XML

Status
Not open for further replies.

dsetzer

Programmer
Jan 29, 2001
4
0
0
US
All programming languages have a for/next or do/while or while/wend or etc.. loops that allow them to do the same thing, incrementing a variable.

I've been looking through XSL reference and haven't been able to find a way do doing this, yet.

What I am trying to do is take XML:
<item>
<min>5</min>
<max>50</max>
<increment>5</increment>
</item>

And have it create 10 <option value=&quot;current_increment&quot;>current_increment</option>. For example:
<option value=&quot;5&quot;>5</option>
<option value=&quot;10&quot;>10</option>
<option value=&quot;15&quot;>15</option>
..etc..
<option value=&quot;45&quot;>45</option>
<option value=&quot;50&quot;>50</option>

Any help as to how to do this in XSL, without doing using XML like:
<item>
<min>5</min>
<max>50</max>
<increment>5</increment>
<steps>
<step>5</step>
<step>10</step>
<step>15</step>
<step>20</step>
<step>25</step>
<step>30</step>
<step>35</step>
<step>40</step>
<step>45</step>
<step>50</step>
</steps>
</item>

Thanks.
 
hi dsetzer

You need this XSL code:
(you must change paths of course)

<xsl:template match=&quot;/&quot;>
<select>
<xsl:call-template name=&quot;option&quot;>
<xsl:with-param name=&quot;val&quot; select=&quot;number(//min)&quot;/>
</xsl:call-template>
</select>
</xsl:template>

<xsl:template name=&quot;option&quot;>
<xsl:param name=&quot;val&quot;/>
<option value=&quot;{$val}&quot;>
<xsl:value-of select=&quot;$val&quot;/>
</option>
<xsl:if test=&quot;number(//max) > $val&quot;>
<xsl:call-template name=&quot;option&quot;>
<xsl:with-param name=&quot;val&quot; select=&quot;$val+//increment&quot;/>
</xsl:call-template>
</xsl:if>
</xsl:template>

Tell me if you'll have problems with it.

Best regards.
Avator
 
Avator -

Thanks for the great post, but, now when I try to transform my XML sheet I'm getting an error:
Code:
Keyword xsl:call-template may not be used in namespace [URL unfurl="true"]http://www.w3.org/TR/WD-xsl.[/URL]

We are using a custom object as a wrapper around the MSXML DOM. If I use it directly, I'm expecting the same error. Does the code you have here work with the MSXML DOM? Should we be using a different namespace declaration other than
Thanks.
 
I change my xsl:stylesheet tag to read:
Code:
<xsl:stylesheet version='1.0' xmlns:xsl=&quot;[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform&quot;>[/URL]

And this fixed the problem. The drop-down lists generate fine and everything!

Thanks for your help. I'll probably have more questions, but, this was a great start.
 
Yes, I use .../1999/XSL/Transform namespace.
Sorry for belated answer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top