I need to build a flat table in text from a hierarchical XML. I need one flat line per meas node. Each meas node has an index number (mN), which refers back to a smaller section which where a label (tL) is kept for each unique possibility of the index number. I want to loop each meas node and use the value of mN attribute to look up the corresponding tL value. The example below delivers the index (mN) numbers properly, but always delivers One for every row:
xml
<root> <cond tN="1" tL="One"/> <cond tN="2" tL="Two"/> <cond tN="3" tL="Three"/> <cond tN="4" tL="Four"/> <cond tN="5" tL="Five"/> <meas mN="1"/> <meas mN="2"/> <meas mN="3"/> <meas mN="4"/> <meas mN="5"/> <meas mN="1"/> <meas mN="2"/> <meas mN="3"/> <meas mN="4"/> <meas mN="5"/> </root> xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output method="text"/> <xsl:template match="/"> <xsl:for-each select="/root/meas"> <xsl:variable name="MeasN"> <xsl:value-of select="@mN"/> </xsl:variable> <xsl:value-of select="$MeasN"/>, <xsl:value-of select="../cond[$MeasN]/@tL"/>. </xsl:for-each> </xsl:template> </xsl:stylesheet> output
1 One 2 One 3 One 4 One 5 One 1 One 2 One 3 One 4 One 5 One