我需要从信封中提取
XML.但我无法得到我想要的输出.
我需要摆脱输出中的命名空间.
我的意见:
<ns1:input xmlns:ns1="http://mysapmle.org/" xmlns="http://othersample.org/">
<sample>
<inner tc="5">Test</inner>
<routine>Always</routine>
</sample>
</ns1:input>
我的预期成果:
<sample>
<inner tc="5">Test</inner>
<routine>Always</routine>
</sample>
我的实际产出:
<sample xmlns="http://othersample.org/">
<inner tc="5">Test</inner>
<routine>Always</routine>
</sample>
我的XSLT:
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:template match="/">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="//sample" />
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
请帮忙.
最佳答案 这应该用于剥离命名空间:
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:template match="/">
<xsl:apply-templates select="*/*" />
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>
但我有点怀疑你需要这样做.如果您要将此附加到的XML使用相同的命名空间,并且这是包含XML的命名空间应该具有的,那么此XML中的命名空间声明应该无关紧要.