I need to use a XSLT file to transform a xml to csv. Thats easy enough.
I also need to count distinct values from a node and insert them to each line. This where I don't know what to do.
The node I need to count you can see in the example below. It is called < Id >.
I basically want to count all of the id's that are unique, and insert the result into each orderline.
Since my example have two < id > nodes with the value 1 and one < id > node with the value 4, the result would be 2.
Thanks in advance for any help at all.
XML:
<?xml version="1.0" encoding="utf-8"?>
<Picked xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<OrderLines>
<OrderLine>
<OrderId>1345
</OrderId>
<Missions>
<Mission>
<ContainerIds>
<Container>
<Id>1
</Id>
</Container>
</ContainerIds>
</Mission>
</Missions>
</OrderLine>
<OrderLine>
<OrderId>13456
</OrderId>
<Missions>
<Mission>
<ContainerIds>
<Container>
<Id>1
</Id>
</Container>
</ContainerIds>
</Mission>
</Missions>
</OrderLine>
<OrderLine>
<OrderId>134567
</OrderId>
<Missions>
<Mission>
<ContainerIds>
<Container>
<Id>4
</Id>
</Container>
</ContainerIds>
</Mission>
</Missions>
</OrderLine>
</OrderLines>
</Picked>
Desired result:
Orderid;Id
1345;2
13456;2
134567;2
XSLT so far:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match='/'>
<xsl:text>Orderid;Id</xsl:text>
<xsl:text> </xsl:text>
<xsl:for-each select="/Picked/OrderLines/OrderLine">
<xsl:value-of select="OrderId"/>
<xsl:text>;</xsl:text>
<xsl:value-of select="Missions/Mission/ContainerIds/Container/Id"/>
<xsl:if test="position()!=last()">
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
My Result so far:
Orderid;Id
1345;1
13456;1
134567;4