Given this source XML:
<output>
<report>
<C01>
<InvID>001</InvID>
<Daily>
<row id="0000">1</row>
<row id="0001">2</row>
<row id="0002">5</row>
<row id="0003">4</row>
</Daily>
</C01>
<C02>
<InvID>002</InvID>
<Daily>
<row id="0000">4</row>
<row id="0001">3</row>
<row id="0002">2</row>
<row id="0003">5</row>
</Daily>
</C02>
<C03>
<InvID>001</InvID>
<Daily>
<row id="0000">3</row>
<row id="0001">7</row>
<row id="0002">2</row>
<row id="0003">4</row>
</Daily>
</C03>
<report>
<output>
How can I produce this output:
<Data invID=001>
<Value>1</Value>
<Value>2</Value>
<Value>5</Value>
<Value>4</Value>
<Value>3</Value>
<Value>7</Value>
<Value>2</Value>
<Value>4</Value>
</Data>
<Data invID=002>
<Value>4</Value>
<Value>3</Value>
<Value>2</Value>
<Value>5</Value>
</Data>
I have been trying to use something like this as the basis, but it feels all wrong:
<xsl:template match="output/report">
<xsl:for-each select="*[starts-with(name(), 'C') and InvID != '']">
<xsl:sort select="InvID" />
<xsl:element name="Data">
<xsl:attribute name="invID">
<xsl:value-of select="InvID" />
</xsl:attribute>
</xsl:element>
</xsl:for-each>
</xsl:template>
I need to aggregate all items that share a common InvID
, output a single Data
element for that group of source elements, and then output all of their row
element values into children of that Data
element (Value
).
Can this be done in XPath 1.0?