Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 9th, 2006, 03:55 PM
karthikpv@gmail.com
Guest
 
Posts: n/a
Default Need to group elements using XSLT

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>
<DslamNameFAA3XDE2</DslamName>
<PortPORT: 1 IF: 2163728</Port>
<CP-Maparccp28:3:66</CP-Map>
<SlotStatusPresent</SlotStatus>
<PIU-x-</PIU>
<ADM-x-</ADM>
</row>
<row>
<No>1</No>
<DslamNameFAA3XDE2</DslamName>
<PortPORT: 2 IF: 2163744</Port>
<CP-Maparccp28:3:66</CP-Map>
<SlotStatusPresent</SlotStatus>
<PIU-x-</PIU>
<ADM-x-</ADM>
</row>
<row>
<No>20</No>
<DslamNameHC5XDE2</DslamName>
<PortPORT: 1 IF: 2032656</Port>
<CP-Mapsltcp1:1:62</CP-Map>
<SlotStatusPresent</SlotStatus>
<PIU-x-</PIU>
<ADM-x-</ADM>
</row>
<row>
<No>20</No>
<DslamNameHC5XDE2</DslamName>
<PortPORT: 2 IF: 2032672</Port>
<CP-Mapsltcp1:1:62</CP-Map>
<SlotStatusPresent</SlotStatus>
<PIU-x-</PIU>
<ADM-x-</ADM>
</row>
<row>
<No>40</No>
<DslamNameGI7XDE1</DslamName>
<PortPORT: 1 IF: 1704976</Port>
<CP-Maparccp33:1:52</CP-Map>
<SlotStatusPresent</SlotStatus>
<PIU-x-</PIU>
<ADM-x-</ADM>
</row>
<row>
<No>40</No>
<DslamNameGI7XDE1</DslamName>
<PortPORT: 2 IF: 1704992</Port>
<CP-Maparccp33:1:52</CP-Map>
<SlotStatusPresent</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">
<xsl:output 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.

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles