1
我试图从转换的XML删除空间中声明空间声明的问题
请到这里:http://xslttest.appspot.com/
输入XML:
<Products xmlns="http://api.company.com.au/Data" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Product>
<Code>BM54</Code>
</Product>
</Products>
XSLT模板
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:d="http://api.company.com.au/Data" exclude-result-prefixes="d">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="d:Product">
<DONE>
<xsl:apply-templates select="@* | node()"/>
</DONE>
</xsl:template>
<xsl:template match="@Product">
<xsl:attribute name="DONE">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
结果是:
<Products xmlns="http://api.company.com.au/Data" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DONE xmlns="">
<Code xmlns="http://api.company.com.au/Data">BM54</Code>
</DONE>
</Products>
我希望它是:
<Products xmlns="http://api.company.com.au/Data" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DONE>
<Code>BM54</Code>
</DONE>
</Products>
请注意,这并不是“删除名称空间” - 实际上,您将“DONE”元素放入正确的名称空间中,以便从父级继承默认名称空间。它所做的是避免取消继承的默认值。这是样本输出中要求的内容,但不是原始海报认为他们要求的内容。 – keshlam
如果您在帖子的底部阅读,OP会列出他的要求。可能是OP想说“我试图从转换后的xml中的一些节点中删除不需要的名称空间声明”。 –
非常感谢这么多:) – Paul