|
next
|
 Subject: XSL to ''normalise Author: Ivan Pedruzzi Date: 11 Oct 2004 12:40 AM
|
Hi Richard,
The following stylesheet should solve your problem
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="PID" match="Generic_Part_II/PIDs/PID" use="concat(@service, @type)"/>
<xsl:key name="PID_children" match="Generic_Part_II/PIDs/PID/*" use="concat(../@service, ../@type, name(.), .)"/>
<xsl:template match="/">
<ASL>
<PIDs>
<!--
- group PID by service + type
- eliminate duplicates
-->
<xsl:apply-templates select="Generic_Part_II/PIDs/PID[ generate-id() = generate-id(key('PID', concat(@service, @type))[1])]"/>
</PIDs>
</ASL>
</xsl:template>
<xsl:template match="PID">
<xsl:copy>
<xsl:copy-of select="@*"/>
<!-- copy common elements -->
<xsl:for-each select="*[count(key('PID_children', concat(../@service, ../@type, name(.), . ))) > 1]">
<xsl:copy-of select="."/>
</xsl:for-each>
<Bytes>
<xsl:for-each select="key('PID', concat(@service, @type))">
<byte>
<xsl:for-each select="*[count(key('PID_children', concat(../@service, ../@type, name(.), . ))) = 1]">
<xsl:copy-of select="."/>
</xsl:for-each>
</byte>
</xsl:for-each>
</Bytes>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
|
|
|