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!

Filter / for-each statement

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
My XML code is like this:
<row>
<name>hans</name>
<age>43</age>
<pr_id>1</pr_id>
</row>
<row>
<selected>1</selected>
<name>jason</name>
<age>22</age>
<pr_id>2</pr_id>
</row>
<row>
<name>timmy</name>
<age>30</age>
<pr_id>2</pr_id>
</row>

With my XSL page i only want to output the <row> tags who
has the same <pr_id> tags like the row tage who has also the <Selected>1</selected> tag.

So in this case, I only want to output

jason
22
2

timmy
30
2

I was planning to do it this way:

<!--## Find out the value of the selected row ##-->

<xsl:for-each select=&quot;row[selected=1]&quot;>
<xsl:variable name=&quot;Luc&quot; select=&quot;pr_id&quot;/>
</xsl:for-each>

<!--## Find those who has equal pr_id's ##-->

<xsl:for-each select=&quot;row[contractid={$Luc}]&quot;>
<!-- here's the output -->
</xsl:for-each>

* But as you'll problably will understand, this doesn't work. Could somebody help me?




 
The reason it doesn't work is because the variable $Luc is lost as soon as you close the first </xsl:for-each> - the general rule is to remember that variables can only be seen inside the tags it appears.

if you just chuck your second <xsl:for-each> inside the first and remove the variable you should get what you need.

(also your 2nd for-each references 'contractid' which isn't in your xml src)
 
Hm doesn't seem to work. I dont get error messages that way but i dont say any output.

Another way of explaining my problem is:
I want some sort of query like : select pr_id from ROW where row.selected = 1

contractid should be pr_id. My mistake.
 
<xsl:for-each select=&quot;row[selected=1]&quot;>
<xsl:variable name=&quot;Luc&quot; select=&quot;pr_id&quot;/>
<xsl:for-each select=&quot;../row[pr_id=$Luc]&quot;>
<xsl:value-of select=&quot;name&quot;/>
</xsl:for-each>
</xsl:for-each>

hth
 
Thanks for your help. I solved my problem. Really geat!

thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top