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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a variable select statement

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello,

I've got a problem with the for-each statement. First the code:
<!--***************************************** -->
<xsl:variable name=&quot;tim&quot;>row</xsl:variable>

<xsl:for-each select=&quot;page/$tim&quot;>
<xsl:variable name=&quot;age&quot; select=&quot;age&quot;/>
<input type=&quot;text&quot; value=&quot;{$age}&quot;>
</xsl:for-each>
<!--***************************************** -->


Well, the for-each statement is not working this way. I think it's abvious what I'm trying to do here so I wont have to explain that. Could somebody tell me the right way to de this?

thanks.
 
I found it out myself: for those who want to know the anser:
the for-each statement should be like this:

<xsl:for-each select=&quot;page/*[name()=$tim]&quot;>
 
i'm not sure about the XML you were using. my example works with this bit:
Code:
<?xml version=&quot;1.0&quot; ?>
<page>
  <row>
    <age>21</age>
    <fname>bob</fname>
    <lname>smith</lname>
  </row>
  <row>
    <age>18</age>
    <fname>sally</fname>
    <lname>noname</lname>
  </row>
</page>

to access every node named &quot;row&quot; by the use of a variable, access every childnode and use the name() function to equate the node name with the value of your variable:
Code:
<xsl:variable name=&quot;tim&quot;>row</xsl:variable>

<xsl:for-each select=&quot;//*[name()=$tim]&quot;>
  <xsl:variable name=&quot;age&quot; select=&quot;age&quot;/>
  <input type=&quot;text&quot; value=&quot;{$age}&quot; /><br/>
</xsl:for-each>

hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top