473,786 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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"?>
<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.

Aug 9 '06 #1
1 1672
Sorting: http://www.dpawson.co.uk/xsl/sect2/N6461.html
More complicated grouping: http://www.dpawson.co.uk/xsl/sect2/N6280.html

XSLT 2.0 adds more support for these operations... but unfortunately 2.0
is not widely available yet.
Aug 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11877
by: Edwin G. Castro | last post by:
Hi, I'm new to XSLT and I'm having a hard time figuring out whether XSLT will do what I need it to do. I have a XML file with a whole bunch of <message> elements. These <message> elements have <!]> in them. I would like to use XSLT to remove the <message> elements whose CDATA (the "...") matches a particular regular expression.
23
4092
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to <foo/>) From XHTML specification:
3
9927
by: Stephan Brunner | last post by:
Hi I have created two flavors of an XSLT stylesheet to transform all attributes of an XML document to elements: They both work as expected with MSXML and XMLSPY but throw an exception ========================= <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"
5
1590
by: inetquestion | last post by:
I've got an xml doc which I'm using xslt to create a flat text configuration file. I need to make some dynamic changes in certain circumstances where some of the elements need to have others substituted in their place. Other elements may need to be added or deleted altogether. So far I'm not seeing how this can be done in xslt...Looking for some sugestions. Right now I'm doing the transform with XML::XSLT in perl, but could use...
1
1357
by: Max Evans | last post by:
I have a XML file, which contains itemid-elements, e.g.: <itemid>3</itemid> <itemid>12</itemid> Now I want to convert these IDs to the corresponding name via XSLT. I thought I could do it this way (XSLT): <xsl:apply-templates select="itemid" /> <xsl:template match="itemid"> <xsl:value-of select="itemnames" /> </xsl:template> And I'd like to have this itemnames-element also inside the XSLT file
2
5253
by: Steveino | last post by:
Hello, Just wondering if anyone could shed any light on this, it's probably me just being silly... I have a dataset that I've used to create an XmlDataDocument, in order to apply XSL. The XSL reformats the XML to another format (still XML, not HTML). This works fine, but whatever I do, I can't get the finally output section to have CDATA elements. I've added a cdata-section-elements tag into the xsl file, but it doesn't seem to have...
1
1330
by: tslettebo | last post by:
Hi all. I've read Michael Kay's "XSLT" book, and used XSLT successfully as an HTML template system at our company (using basically the "fill-in-the-blanks" pattern of XSLT use: A template matching the root node, containing the HTML page, with lots of <xsl:value-of.../>, etc.). However, I've recently got a task that got me stumped, and I don't know if I'm missing something obvious, but quite frankly, I don't know where in the sea of...
0
381
by: karthikpv | last post by:
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.
1
13387
by: n.phelge | last post by:
I'm using XSLT and .NET Framework 1.1 to try to transform XML to group by multiple values, and I'm not succeeding. I have source XML that looks like the following: <Data> <Flavor> <Name>Vanilla</Name> <StartDate>20070704</StartDate> <EndDate>20071231</EndDate> </Flavor>
0
9496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9961
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.