您可能想要一些特定于 BizTalk 的东西,而我对 BizTalk 一无所知,但这可能对您有所帮助。
给定一个输入文档...
<customers>
<customer>
<customernum>1</customernum>
<shipaddrcity>Cairns</shipaddrcity>
<shipaddrstate>QLD</shipaddrstate>
<shipaddrzip>b</shipaddrzip>
<billaddrcity>Sydney</billaddrcity>
<billaddrstate>NSW</billaddrstate>
<billaddrzip>c</billaddrzip>
</customer>
<customer>
<customernum>2</customernum>
<shipaddrcity>d</shipaddrcity>
<shipaddrstate>WA</shipaddrstate>
<shipaddrzip>e</shipaddrzip>
<billaddrcity>Melbourne</billaddrcity>
<billaddrstate>Vic</billaddrstate>
<billaddrzip>f</billaddrzip>
</customer>
</customers>
... 这个 XSLT 1.0 样式表 ...
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="customer">
<xsl:copy>
<xsl:apply-templates select="@*|node()[not(
self::shipaddrstate|
self::shipaddrzip |
self::billaddrstate|
self::billaddrzip )]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="shipaddrcity">
<addr>
<type>ship</type>
<city><xsl:value-of select="." /></city>
<xsl:apply-templates select="../(shipaddrstate|shipaddrzip)" />
</addr>
</xsl:template>
<xsl:template match="billaddrcity">
<addr>
<type>bill</type>
<city><xsl:value-of select="." /></city>
<xsl:apply-templates select="../(billaddrstate|billaddrzip)" />
</addr>
</xsl:template>
<xsl:template match="shipaddrstate|billaddrstate">
<state><xsl:value-of select="." /></state>
</xsl:template>
<xsl:template match="shipaddrzip|billaddrzip">
<zip><xsl:value-of select="." /></zip>
</xsl:template>
</xsl:transform>
...当应用于输入文档时,将产生...
<customers>
<customer>
<customernum>1</customernum>
<addr>
<type>ship</type>
<city>Cairns</city>
<state>QLD</state>
<zip>b</zip>
</addr>
<addr>
<type>bill</type>
<city>Sydney</city>
<state>NSW</state>
<zip>c</zip>
</addr>
</customer>
<customer>
<customernum>2</customernum>
<addr>
<type>ship</type>
<city>d</city>
<state>WA</state>
<zip>e</zip>
</addr>
<addr>
<type>bill</type>
<city>Melbourne</city>
<state>Vic</state>
<zip>f</zip>
</addr>
</customer>
</customers>