我有以下XML,我使用EDIFabric和EDI文件转换为XML。
<?xml version="1.0" encoding="UTF-8"?>
<M_856 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="www.edifabric.com/x12">
<S_N3>
<D_166_1>UNION SQUARE IND PK</D_166_1>
<D_166_2>909 KATIE COURT</D_166_2>
</S_N3>
<S_N4>
<D_19_1>Harrisburg</D_19_1>
<D_156_2>PA</D_156_2>
<D_116_3>17109</D_116_3>
<D_26_4>US</D_26_4>
</S_N4>
<S_SE>
<D_96_1>22</D_96_1>
<D_329_2>1845</D_329_2>
</S_SE>
</M_856>
我想提取所有S_N4节点,如下所示:
<City>Harrisburg</City>
<State>PA</State>
<PostalCode>17109</PostalCode>
<Country>US</Country>
需要什么样的XSLT转换?
答案 0 :(得分:0)
下面会这样做,将Root重命名为root:
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl s0" version="1.0" xmlns:s0="www.edifabric.com/x12">
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
<xsl:template match="/">
<xsl:apply-templates select="/s0:M_856" />
</xsl:template>
<xsl:template match="/s0:M_856">
<Root>
<City>
<xsl:value-of select="s0:S_N4/s0:D_19_1/text()" />
</City>
<State>
<xsl:value-of select="s0:S_N4/s0:D_156_2/text()" />
</State>
<PostalCode>
<xsl:value-of select="s0:S_N4/s0:D_116_3/text()" />
</PostalCode>
<Country>
<xsl:value-of select="s0:S_N4/s0:D_26_4/text()" />
</Country>
</Root>
</xsl:template>
</xsl:stylesheet>