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!

for-each loop to get value above

Status
Not open for further replies.

girky

Programmer
Oct 24, 2002
72
0
0
US
Hello,
I'm trying to loop through values in an above node to get the "columnname" and can't seem to get the syntax correct. Any help is appreciated!

XML:
<Data>
<Check>
<DetailedData>
<ColumnNames>
<ColumnName>UserName</ColumnName>
<ColumnName>Status</ColumnName>
</ColumnNames>
<DataRows>
<DataRow>
<DataValue>USER</DataValue>
<DataValue>ENABLED</DataValue>
</DataRow>
<DataRow>
<DataValue>USER2</DataValue>
<DataValue>DISABLED</DataValue>
</DataRow>
</DetailedData>
</Check>
<Check>
<DetailedData>
<ColumnNames>
<ColumnName>Type</ColumnName>
<ColumnName>Location</ColumnName>
<ColumnName>Status</ColumnName>
</ColumnNames>
<DataRows>
<DataRow>
<DataValue>1</DataValue>
<DataValue>US</DataValue>
<DataValue>Disabled</DataValue>
</DataRow>
<DataRow>
<DataValue>6</DataValue>
<DataValue>US</DataValue>
<DataValue>enabled</DataValue>
</DataRow>
</DetailedData>
</Check>
</Data>


XSL:
<xsl:template match="/">
<html>
<body>
<table><caption>Table1</caption>
<tr>
<td>FieldValue</td>
<td>FieldName</td>
</tr>

<xsl:for-each select="Data/Check/DetailedData/DataRows/DataRow/DataValue">
<tr>
<td><xsl:value-of select="."/></td>
<td> ***need value of column name here*** </td>
</tr>
</xsl:for-each>

</table>
</body>
</html>
</xsl:template>


Final Desired Output:
FieldValue FieldName
UserName User
Status Enabled
UserName User2
Status Disabled
Type 1
Location US
Status Disabled
Type 6
Location US
Status enabled
 
I figured this out for future reference:
I store the current position in a variable then just to that position on the above node

<xsl:variable name="position_number" select="count(preceding-sibling::*) + 1"/>
<xsl:value-of select="../../../ColumnNames/ColumnName[$position_number]"/>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top