![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Need to group elements using XSLT [Thread Next] Re: Need to group elements using XSLTTo: NULL Date: 8/10/2006 6:58:00 PM If you want to use for-each-group then you'll need to use XSLT version 2.0 which probably means using the Saxon processor, either in Java or the .NET version. For version 1.0 grouping I recommend this site: http://www.jenitennison.com/xslt/grouping/muenchian.xml If that doesn't help let us know. -- Joe Fawcett - XML MVP http://joe.fawcett.name <karthikpv@g...> wrote in message news:1155135492.115898.173580@m...... > 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"> > <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. > | ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
