I have the following XML:
<types>
<type>
<name>derived</name>
<superType>base</superType>
<properties>
<property>
<name>B1</name>
</property>
<property>
<name>D1</name>
</property>
</properties>
</type>
<type>
<name>base</name>
<properties>
<property>
<name>B1</name>
</property>
</properties>
</type>
</types>
Which I want to tranform to this output:
derived
D1
base
B1
Note that node /types/type[name='derived']/properties/property[name='B1'] has been skipped since it exists in the base type as: /types/type[name='base']/properties/property[name='B1'].
I have come up with this XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<!-- Do nothing for base class properties -->
<!-- Wouldn't be necessary if the match criteria could be applied in the select -->
<xsl:template match="property"/>
<xsl:template match="property[not(//type[name=current()/../../superType]/properties/property[name=current()/name])]">
<xsl:text>	</xsl:text>
<xsl:value-of select="name"/>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="types/type">
<xsl:value-of select="name"/>
<xsl:text> </xsl:text>
<xsl:apply-templates select="./properties"/>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
This works (using the XML Tools plug-in in Notepad++), but the not(//type[name=current()/../../superType]/properties/property[name=current()/name]) XPath expression is horribly inefficient: when applied to a 200K line XML file, the transform takes 280 seconds. Without this XPath expression the transform only takes 2 seconds.
Is there some way to speed this up?
Measure this for speed…