Obalix's answer may not work in the case there are multiple paramList
elements in the input document. I assume this may interest the poster if the document describe a software interface where there are multiple procedures with a paramList
for each.
Here is a sample input:
<root>
<func name="one">
<paramList>
<param name="y" out="true"/>
<param name="y" in="true"/>
<param name="z" out="true"/>
<param name="x" in="true"/>
</paramList>
</func>
<func name="two">
<paramList>
<param name="z" in="true"/>
</paramList>
</func>
</root>
Here is my proposed stylesheet, built on Obalix's answer. The trick is to use a local key id containing the ID of the paramList
element.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="xml" indent="yes"/>
<xsl:key name="paramsByName" match="param" use="concat(generate-id(..), '/', @name)"/>
<xsl:template match="paramList">
<xsl:copy>
<xsl:variable name="id" select="generate-id(.)"/>
<xsl:for-each select="param[count(. | key('paramsByName', concat($id, '/', @name))[1]) = 1]">
<xsl:copy>
<xsl:copy-of select="key('paramsByName', concat($id, '/', @name))/@*"/>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>