Re: [xsl] Conditional Merging of the node based child value match

Subject: Re: [xsl] Conditional Merging of the node based child value match
From: Senthilkumaravelan Krishnanatham <senthil@xxxxxxxxx>
Date: Mon, 18 Sep 2006 10:46:26 -0700
Thank you very much.
Regards,
Senthil
On Sep 16, 2006, at 12:55 AM, Abel Braaksma wrote:

Senthilkumaravelan Krishnanatham wrote:

Hi All,
I have following xml as my input and I need to group the item number with the corresponding line item number and form the out as mentioned below.
I would like to how to group the nodes based the condition and form the output.
Hi Senthil,

I don't see such a thing as a line item number in your code, but it appears to me you are actually talking about ITEM_NUMBER that must equal, and you want to group the CTO_INFO elements inside the CTOS section, when these ITEM_NUMBER match. Something like that. If that's so, here's a stylesheet that (almost) produces that output you have. You probably want to tweak it a bit. For instance, it currently outputs an empty CTOS element when there are no matchin ITEM_NUMBER nodes.

Have fun with it,

Cheers,
Abel Braaksma
http://abelleba.metacarpus.com

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ Transform">
<xsl:output indent="yes" />
<xsl:template match="/">
<ORDER>
<xsl:apply-templates select="ORDER/TAB_ITEM" />
</ORDER>
</xsl:template>
<xsl:template match="TAB_ITEM">
<xsl:variable name="nr" select="ITEM_NUMBER" />
<TAB_ITEM>
<xsl:copy-of select="*" />
<CTOS>
<xsl:apply-templates select="../TAB_CTO[ITEM_NUMBER = $nr]/CTO_INFO" />
</CTOS>
</TAB_ITEM>
</xsl:template>
<xsl:template match="CTO_INFO">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>

Current Thread