Hi, I'm a newbie to the world of XML/XSLT and I've been tasked with processing a XML file containing orders and effectively turning it into a headers and lines scenario. This is not exactly the case but it best demonstrates what I need to do.
I will have an XML file as follows:
<Orders>
<OrderDetail>
<OrderNo>123</OrderNo>
<ProductId>ABC1</ProductId>
</OrderDetail>
<OrderDetail>
<OrderNo>124</OrderNo>
<ProductId>ABC1</ProductId>
</OrderDetail>
<OrderDetail>
<OrderNo>123</OrderNo>
<ProductId>ABC2</ProductId>
</OrderDetail>
<OrderDetail>
<OrderNo>124</OrderNo>
<ProductId>ABC3</ProductId>
</OrderDetail>
</Orders>
And I need to get output similar to this:
<OrderHeader>
<OrderNo>123</OrderNo>
</OrderHeader>
<OrderLine>
<OrderNo>123</OrderNo>
<ProductId>ABC1</ProductId>
</OrderLine>
<OrderLine>
<OrderNo>123</OrderNo>
<ProductId>ABC2</ProductId>
</OrderLine>
<OrderHeader>
<OrderNo>124</OrderNo>
</OrderHeader>
<OrderLine>
<OrderNo>124</OrderNo>
<ProductId>ABC1</ProductId>
</OrderLine>
<OrderLine>
<OrderNo>124</OrderNo>
<ProductId>ABC3</ProductId>
</OrderLine>
Does anybody know how I can achieve this?
I think I need to do some use of xsl:sort to sort the stuff in the first place and then some variation of this code to only selectively output headers
<xsl:variable name="unique-list"
select="//OrderNo[not(.=following::OrderNo)]" />
<xsl:for-each select="$unique-list">
<xsl:value-of select="." />
</xsl:for-each>
Now please bear with me. I am an experienced procedural programmer and I'm trying to get into this (Its real BTW not 'homework').
Regards
Razor
I will have an XML file as follows:
<Orders>
<OrderDetail>
<OrderNo>123</OrderNo>
<ProductId>ABC1</ProductId>
</OrderDetail>
<OrderDetail>
<OrderNo>124</OrderNo>
<ProductId>ABC1</ProductId>
</OrderDetail>
<OrderDetail>
<OrderNo>123</OrderNo>
<ProductId>ABC2</ProductId>
</OrderDetail>
<OrderDetail>
<OrderNo>124</OrderNo>
<ProductId>ABC3</ProductId>
</OrderDetail>
</Orders>
And I need to get output similar to this:
<OrderHeader>
<OrderNo>123</OrderNo>
</OrderHeader>
<OrderLine>
<OrderNo>123</OrderNo>
<ProductId>ABC1</ProductId>
</OrderLine>
<OrderLine>
<OrderNo>123</OrderNo>
<ProductId>ABC2</ProductId>
</OrderLine>
<OrderHeader>
<OrderNo>124</OrderNo>
</OrderHeader>
<OrderLine>
<OrderNo>124</OrderNo>
<ProductId>ABC1</ProductId>
</OrderLine>
<OrderLine>
<OrderNo>124</OrderNo>
<ProductId>ABC3</ProductId>
</OrderLine>
Does anybody know how I can achieve this?
I think I need to do some use of xsl:sort to sort the stuff in the first place and then some variation of this code to only selectively output headers
<xsl:variable name="unique-list"
select="//OrderNo[not(.=following::OrderNo)]" />
<xsl:for-each select="$unique-list">
<xsl:value-of select="." />
</xsl:for-each>
Now please bear with me. I am an experienced procedural programmer and I'm trying to get into this (Its real BTW not 'homework').
Regards
Razor