Hi,
I am trying to group nodes in a huge xml file by one of the common
fields. I have tried using "for-each-group" and "group-by" but am
unable to get it working.
Here, I have a list of Ports under each DSLAM entry and would hence
like to group in a hierarchy all such Ports under each of these DSLAM
entries as shown below.
Here's a sample xml file (similar to the one I am trying to transform,
but simplified to remove a lot of junk fields) and the required xml
output -
----Sample XML file-----
<?xml version="1.0" encoding="UTF-8"?>
<ConvertCSVToXM L>
<row>
<No>1</No>
<DslamNameFAA3X DE2</DslamName>
<PortPORT: 1 IF: 2163728</Port>
<CP-Maparccp28:3:66 </CP-Map>
<SlotStatusPres ent</SlotStatus>
<PIU-x-</PIU>
<ADM-x-</ADM>
</row>
<row>
<No>1</No>
<DslamNameFAA3X DE2</DslamName>
<PortPORT: 2 IF: 2163744</Port>
<CP-Maparccp28:3:66 </CP-Map>
<SlotStatusPres ent</SlotStatus>
<PIU-x-</PIU>
<ADM-x-</ADM>
</row>
<row>
<No>20</No>
<DslamNameHC5XD E2</DslamName>
<PortPORT: 1 IF: 2032656</Port>
<CP-Mapsltcp1:1:62</CP-Map>
<SlotStatusPres ent</SlotStatus>
<PIU-x-</PIU>
<ADM-x-</ADM>
</row>
<row>
<No>20</No>
<DslamNameHC5XD E2</DslamName>
<PortPORT: 2 IF: 2032672</Port>
<CP-Mapsltcp1:1:62</CP-Map>
<SlotStatusPres ent</SlotStatus>
<PIU-x-</PIU>
<ADM-x-</ADM>
</row>
<row>
<No>40</No>
<DslamNameGI7XD E1</DslamName>
<PortPORT: 1 IF: 1704976</Port>
<CP-Maparccp33:1:52 </CP-Map>
<SlotStatusPres ent</SlotStatus>
<PIU-x-</PIU>
<ADM-x-</ADM>
</row>
<row>
<No>40</No>
<DslamNameGI7XD E1</DslamName>
<PortPORT: 2 IF: 1704992</Port>
<CP-Maparccp33:1:52 </CP-Map>
<SlotStatusPres ent</SlotStatus>
<PIU-x-</PIU>
<ADM-x-</ADM>
</row>
</ConvertCSVToXML >
----------------
The xsl I am using is like this -
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="E:\TDC\Co de\JAXP
Parsing\DOM_CSV 2XML\P_20060519-16-Transform.xsl"? >
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="ConvertC SVToXML">
<UDM xmlns="http://www.test.com/udm" xmlns:udm="http ://www.test.com"
versionNumber=" 1.0" generatedBy="UD MG" source="RManage r">
<xsl:for-each select="//row">
<xsl:element name="node">
<xsl:attribut e name="UDMID"><x sl:value-of
select="positio n()"/></xsl:attribute>
<xsl:attribut e name="UPK"><xsl :value-of
select="./DslamName"/></xsl:attribute>
<xsl:element name="card">
<xsl:attribut e name="UDMID"><x sl:value-of
select="positio n()"/></xsl:attribute>
<xsl:attribut e name="UPK"><xsl :value-of
select="./DslamName"/></xsl:attribute>
<xsl:attribut e name="DslamName "><xsl:valu e-of
select="./DslamName"/></xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:for-each>
</UDM>
</xsl:template>
</xsl:stylesheet>
-----------------
The required output xml after transformation would be as below ---
-------------
<?xml version="1.0" encoding="UTF-8"?>
<UDM xmlns="http://www.test.com/udm" xmlns:udm="http ://www.test.com"
versionNumber=" 1.0" generatedBy="UD MG" source="TManage r">
<node UPK="FAA3XDE2">
<card UDMID="2" UPK="PORT: 1 IF: 2163728" DslamName="FAA3 XDE2"/>
<card UDMID="3" UPK="PORT: 2 IF: 2163744" DslamName="FAA3 XDE2"/>
</node>
<node UPK="HC5XDE2">
<card UDMID="2" UPK="PORT: 1 IF: 2032656" DslamName="HC5X DE2"/>
<card UDMID="3" UPK="PORT: 2 IF: 2032672" DslamName="HC5X DE2"/>
</node>
<node UPK="GI7XDE1">
<card UDMID="2" UPK="PORT: 1 IF: 1704976" DslamName="GI7X DE1"/>
<card UDMID="3" UPK="PORT: 2 IF: 1704992" DslamName="GI7X DE1"/>
</node>
</UDM>
Can someone help me get this to work. Any help would be appreciated.
Thanks & Regards,
Sudesh Acharya.