私は次の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>
この出力に変換したいもの:
derived
D1
base
B1
ノード/types/type[name='derived']/properties/property[name='B1']
は基本タイプに次のように存在するため、スキップされていることに注意してください/types/type[name='base']/properties/property[name='B1']
。
私はこの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>
これは(Notepad ++のXMLツールプラグインを使用して)機能しますが、not(//type[name=current()/../../superType]/properties/property[name=current()/name])
XPath式はひどく非効率的です。200K行のXMLファイルに適用すると、変換に280秒かかります。このXPath式がない場合、変換には2秒しかかかりません。
これをスピードアップする方法はありますか?