这种转变:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<rows>
<xsl:apply-templates/>
</rows>
</xsl:template>
<xsl:template match=
"property[not(substring-before(name,'_')
=
substring-before(preceding-sibling::*[1]/name,'_'))]">
<row>
<xsl:apply-templates mode="inRow" select=
"/*/property[substring-before(name,'_') = substring-before(current(),'_')]"/>
</row>
</xsl:template>
<xsl:template match="property" mode="inRow">
<xsl:element name="{substring-after(name,'_')}"><xsl:value-of select="value"/></xsl:element>
</xsl:template>
<xsl:template match="property"/>
</xsl:stylesheet>
应用于提供的 XML 文档时:
<properties>
<property>
<name>Row1_Field1</name>
<value>Data Value Sample</value>
</property>
<property>
<name>Row1_Field2</name>
<value>Data Value Sample</value>
</property>
<property>
<name>Row2_Field1</name>
<value>Data Value Sample</value>
</property>
<property>
<name>Row2_Field2</name>
<value>Data Value Sample</value>
</property>
</properties>
产生想要的正确结果:
<rows>
<row>
<Field1>Data Value Sample</Field1>
<Field2>Data Value Sample</Field2>
</row>
<row>
<Field1>Data Value Sample</Field1>
<Field2>Data Value Sample</Field2>
</row>
</rows>