Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Need to group elements using XSLT

From: karthikpv@-----.---
To: NULL
Date: 8/9/2006 7:58:00 AM

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.



transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent