Hi Michael
Point taken. But frankly speaking, i had actually reduced the file considerably and also just given a very small percentage of what my actual requirement was. If you go through the file, you will find out that most of the nodes are repeated.
But as you said i will further narrow down my requirement and ask you the part which i am finding harder than the rest. Basically i want to do a multiple grouping.
Let me make the target XML and Source XML smaller.
Source XML
<?xml version="1.0" encoding="UTF-8"?>
<Ship>
<Address_Info>
<AddressQualifier>WE</AddressQualifier>
<Partner>121121</Partner>
</Address_Info>
<Address_Info>
<AddressQualifier>WE</AddressQualifier>
<Partner>121100</Partner>
</Address_Info>
<Address_Info>
<AddressQualifier>ZY</AddressQualifier>
<Partner>121122</Partner>
</Address_Info>
<Address_Info>
<AddressQualifier>OSP</AddressQualifier>
<Partner>121122</Partner>
</Address_Info>
<Address_Info>
<AddressQualifier>WE</AddressQualifier>
<Partner>121100</Partner>
</Address_Info>
</Ship>
Target XML after transformation
<?xml version="1.0" encoding="UTF-8"?>
<Ship>
<Address_Info>
<AddressQualifier>WE</AddressQualifier>
<Partner>121121</Partner>
</Address_Info>
<Address_Info>
<AddressQualifier>WE</AddressQualifier>
<Partner>121100</Partner>
</Address_Info>
</Ship>
I have to initially do a grouping by Partner, and then by AddressQualifier. I have to only identify AddressQualifier with value 'WE' and if it has same Partner group it together and show as output.
I tried the Muenchian method to do multiple grouping but i failed,
i tried something like this (a part of my coding...),
<xsl:key name="Partner" match="Ship/Address_Info" use="Partner"/>
<xsl:key name="AddressQualifier" match="Ship/Address_Info" use="AddressQualifier"/>
<xsl:template match="/">
<Ship>
<xsl:for-each select="Ship/Address_Info[generate-id(.) = generate-id(key('Partner', Partner)[1]) ]">
<xsl:variable name="group" select="key('AddressQualifier', AddressQualifier)"/>
<xsl:variable name="AQualifier">
<xsl:value-of select="AddressQualifier"/>
</xsl:variable>
<Address_Info>
<AddressQualifier>
<xsl:value-of select="$AQualifier"/>
</AddressQualifier>
</Address_Info>
</xsl:for-each>
</Ship>
</xsl:template>
</xsl:stylesheet>
Can you let me know the right way of doing multiple grouping.
thanks
Sammy
Quote:
quote:Originally posted by mhkay
A little bit of advice on posting questions.
Firstly, try to reduce the size of the files. No-one wants to wade through all this. It must be possible to extract the essence of the problem into a smaller example.
Secondly, show your efforts to solve the problem, even if they don't work. To help you solve this problem, I need to understand why you found it difficult, which I can't do without seeing your attempts to solve it.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|