I am making a table where the header names are from the header element, and the data is obtained from the attributes of the reportdata elements. However, I do not know the names of the attributes: Value1, Value2, ect.. ahead of time. The names of the attributes are generated and stored into the FieldName attribute which is inside of the column elements inside of the reportnode.
I have not been able to find a way to make an XPath that uses the generated FieldNames and obtains the corresponding attribute's value from reportdata. Any ideas? Or is this not possible.
The following is the XML:
<report>
<reportparameters>
<header Order="1" HeaderName="Day_1" />
<header Order="2" HeaderName="Day_2" />
<header Order="3" HeaderName="Day_3" />
<header Order="4" HeaderName="Total" />
<reportnode ColumnCount="4">
<column Order="1" FieldName="Value1" />
<column Order="2" FieldName="Value2" />
<column Order="3" FieldName="Value3" />
<column Order="4" FieldName="TotalValue" />
</reportnode>
</reportparameters>
<reportdata Value1="0" Value2="0" Value3="0" TotalValue="0"/>
<reportdata Value1="0" Value2="0" Value3="0" TotalValue="0"/>
<reportdata Value1="0" Value2="0" Value3="0" TotalValue="0"/>
<reportdata Value1="0" Value2="0" Value3="0" TotalValue="0"/>
<reportdata Value1="0" Value2="0" Value3="0" TotalValue="0"/>
</report>
The XSL attempt:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no"/>
<xsl:template match="/">
<report>
<row>
<xsl:for-each select="/report/reportparameters/header">
<xsl:variable name="columnCounter" select="position()"/>
<xsl:element name="{./@HeaderName}">
<xsl:for-each select="/report/reportdata">
<xsl:value-of select="@{../reportparameters/reportnode/column[@Order=$columnCounter+1]/@FieldName}"/>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</row>
</report>
</xsl:template>
</xsl:stylesheet>