Hi Andrin,
the problem interested me actually(there are many situations where the technique will be useful), so I tried to solve it entirely instead of giving a hint ;)
Here is the stylesheet:
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="id"/>
<xsl:output indent="yes" method="xml"/>
<xsl:variable name="global-settings" select="/conf/global/settings/*"/>
<xsl:template match="/">
<conf>
<xsl:apply-templates select="conf/instance[@id = $id]"/>
</conf>
</xsl:template>
<xsl:template match="instance/settings">
<xsl:variable name="children" select="*"/>
<xsl:variable name="local-setting-names">
<xsl:for-each select="$children">
<xsl:element name="{name(.)}">
<xsl:value-of select="name(.)"/>
</xsl:element>
</xsl:for-each>
</xsl:variable>
<settings>
<xsl:copy-of select="$children | $global-settings[not(name() = $local-setting-names/*)]"/>
</settings>
</xsl:template>
</xsl:stylesheet>
The stylesheet requires RTF-to-nodeset conversion mechanism: I used Saxon 6.5.2 and put the "version" attribute value equal to 1.1 (this is sufficient for Saxon to implicitly perform any such conversion if needed; for other XSLT processors you have to use vendor's node-set(RTF) function explicitly, if it's supported of course). However, it's interesting to see a stylesheet which will solve the probelm without using a temporary tree.
Regards,
Armen
|