K
karthikpv
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"?>
<ConvertCSVToXML>
<row>
<No>1</No>
<DslamName> FAA3XDE2</DslamName>
<Port> PORT: 1 IF: 2163728</Port>
<CP-Map> arccp28:3:66</CP-Map>
<SlotStatus> Present</SlotStatus>
<PIU> -x-</PIU>
<ADM> -x-</ADM>
</row>
<row>
<No>1</No>
<DslamName> FAA3XDE2</DslamName>
<Port> PORT: 2 IF: 2163744</Port>
<CP-Map> arccp28:3:66</CP-Map>
<SlotStatus> Present</SlotStatus>
<PIU> -x-</PIU>
<ADM> -x-</ADM>
</row>
<row>
<No>20</No>
<DslamName> HC5XDE2</DslamName>
<Port> PORT: 1 IF: 2032656</Port>
<CP-Map> sltcp1:1:62</CP-Map>
<SlotStatus> Present</SlotStatus>
<PIU> -x-</PIU>
<ADM> -x-</ADM>
</row>
<row>
<No>20</No>
<DslamName> HC5XDE2</DslamName>
<Port> PORT: 2 IF: 2032672</Port>
<CP-Map> sltcp1:1:62</CP-Map>
<SlotStatus> Present</SlotStatus>
<PIU> -x-</PIU>
<ADM> -x-</ADM>
</row>
<row>
<No>40</No>
<DslamName> GI7XDE1</DslamName>
<Port> PORT: 1 IF: 1704976</Port>
<CP-Map> arccp33:1:52</CP-Map>
<SlotStatus> Present</SlotStatus>
<PIU> -x-</PIU>
<ADM> -x-</ADM>
</row>
<row>
<No>40</No>
<DslamName> GI7XDE1</DslamName>
<Port> PORT: 2 IF: 1704992</Port>
<CP-Map> arccp33:1:52</CP-Map>
<SlotStatus> Present</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\Code\JAXP
Parsing\DOM_CSV2XML\P_20060519-16-Transform.xsl"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="ConvertCSVToXML">
<UDM xmlns="http://www.test.com/udm" xmlns:udm="http://www.test.com"
versionNumber="1.0" generatedBy="UDMG" source="RManager">
<xsl:for-each select="//row">
<xsl:element name="node">
<xsl:attribute name="UDMID"><xsl:value-of
select="position()"/></xsl:attribute>
<xsl:attribute name="UPK"><xsl:value-of
select="./DslamName"/></xsl:attribute>
<xsl:element name="card">
<xsl:attribute name="UDMID"><xsl:value-of
select="position()"/></xsl:attribute>
<xsl:attribute name="UPK"><xsl:value-of
select="./DslamName"/></xsl:attribute>
<xsl:attribute name="DslamName"><xsl:value-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="UDMG" source="TManager">
<node UPK="FAA3XDE2">
<card UDMID="2" UPK="PORT: 1 IF: 2163728" DslamName="FAA3XDE2"/>
<card UDMID="3" UPK="PORT: 2 IF: 2163744" DslamName="FAA3XDE2"/>
</node>
<node UPK="HC5XDE2">
<card UDMID="2" UPK="PORT: 1 IF: 2032656" DslamName="HC5XDE2"/>
<card UDMID="3" UPK="PORT: 2 IF: 2032672" DslamName="HC5XDE2"/>
</node>
<node UPK="GI7XDE1">
<card UDMID="2" UPK="PORT: 1 IF: 1704976" DslamName="GI7XDE1"/>
<card UDMID="3" UPK="PORT: 2 IF: 1704992" DslamName="GI7XDE1"/>
</node>
</UDM>
Can someone help me get this to work. Any help would be appreciated.
Thanks & Regards,
Sudesh Acharya.
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"?>
<ConvertCSVToXML>
<row>
<No>1</No>
<DslamName> FAA3XDE2</DslamName>
<Port> PORT: 1 IF: 2163728</Port>
<CP-Map> arccp28:3:66</CP-Map>
<SlotStatus> Present</SlotStatus>
<PIU> -x-</PIU>
<ADM> -x-</ADM>
</row>
<row>
<No>1</No>
<DslamName> FAA3XDE2</DslamName>
<Port> PORT: 2 IF: 2163744</Port>
<CP-Map> arccp28:3:66</CP-Map>
<SlotStatus> Present</SlotStatus>
<PIU> -x-</PIU>
<ADM> -x-</ADM>
</row>
<row>
<No>20</No>
<DslamName> HC5XDE2</DslamName>
<Port> PORT: 1 IF: 2032656</Port>
<CP-Map> sltcp1:1:62</CP-Map>
<SlotStatus> Present</SlotStatus>
<PIU> -x-</PIU>
<ADM> -x-</ADM>
</row>
<row>
<No>20</No>
<DslamName> HC5XDE2</DslamName>
<Port> PORT: 2 IF: 2032672</Port>
<CP-Map> sltcp1:1:62</CP-Map>
<SlotStatus> Present</SlotStatus>
<PIU> -x-</PIU>
<ADM> -x-</ADM>
</row>
<row>
<No>40</No>
<DslamName> GI7XDE1</DslamName>
<Port> PORT: 1 IF: 1704976</Port>
<CP-Map> arccp33:1:52</CP-Map>
<SlotStatus> Present</SlotStatus>
<PIU> -x-</PIU>
<ADM> -x-</ADM>
</row>
<row>
<No>40</No>
<DslamName> GI7XDE1</DslamName>
<Port> PORT: 2 IF: 1704992</Port>
<CP-Map> arccp33:1:52</CP-Map>
<SlotStatus> Present</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\Code\JAXP
Parsing\DOM_CSV2XML\P_20060519-16-Transform.xsl"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="ConvertCSVToXML">
<UDM xmlns="http://www.test.com/udm" xmlns:udm="http://www.test.com"
versionNumber="1.0" generatedBy="UDMG" source="RManager">
<xsl:for-each select="//row">
<xsl:element name="node">
<xsl:attribute name="UDMID"><xsl:value-of
select="position()"/></xsl:attribute>
<xsl:attribute name="UPK"><xsl:value-of
select="./DslamName"/></xsl:attribute>
<xsl:element name="card">
<xsl:attribute name="UDMID"><xsl:value-of
select="position()"/></xsl:attribute>
<xsl:attribute name="UPK"><xsl:value-of
select="./DslamName"/></xsl:attribute>
<xsl:attribute name="DslamName"><xsl:value-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="UDMG" source="TManager">
<node UPK="FAA3XDE2">
<card UDMID="2" UPK="PORT: 1 IF: 2163728" DslamName="FAA3XDE2"/>
<card UDMID="3" UPK="PORT: 2 IF: 2163744" DslamName="FAA3XDE2"/>
</node>
<node UPK="HC5XDE2">
<card UDMID="2" UPK="PORT: 1 IF: 2032656" DslamName="HC5XDE2"/>
<card UDMID="3" UPK="PORT: 2 IF: 2032672" DslamName="HC5XDE2"/>
</node>
<node UPK="GI7XDE1">
<card UDMID="2" UPK="PORT: 1 IF: 1704976" DslamName="GI7XDE1"/>
<card UDMID="3" UPK="PORT: 2 IF: 1704992" DslamName="GI7XDE1"/>
</node>
</UDM>
Can someone help me get this to work. Any help would be appreciated.
Thanks & Regards,
Sudesh Acharya.