替换XML标签下面我有XML通过XSLT映射
<?xml version="1.0" encoding="UTF-8"?>
<ConnectInvoice type="INVOICE" xmlns="http://www.scoobydoo.com/xml/ns/ocp">
<FileSize id="78447274">
<FileHeader>
<FileNumber>15043662</FileNumber>
</FileHeader>
</FileSize>
</ConnectInvoice>
这就需要下面的结构转换为:
<?xml version="1.0" encoding="UTF-8"?>
<ConnectInvoice type="INVOICE" xmlns="http://www.scoobydoo.com/xml/ns/ocp">
<Invoice id="78447274">
<FileHeader>
<FileNumber>15043662</FileNumber>
</FileHeader>
</Invoice>
</ConnectInvoice>
请注意, “ID” 该值是动态的。
如果xmlns =“http://www.scoobydoo.com/xml/ns/ocp”在XML中不存在,但XSLT在上述xml位于XML中时不执行任何操作,则XSLT映射工作正常。有人可以帮我解决我的XSLT映射
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="FileSize">
<Invoice><xsl:apply-templates select="node()|@*"/></Invoice>
</xsl:template>
</xsl:stylesheet>
非常感谢
更新:
如果我用下面的XSLT。 XML标记文件大小是过得去发票(这是我想要的)替换,但我也得到它(<Invoice id="78447273" xmlns:sd="scoobydoo.com/xml/ns/ocp">
)命名空间,我不想
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:sd="scoobydoo.com/xml/ns/ocp"; xmlns:xsl="w3.org/1999/XSL/Transform">;
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="sd:FileSize">
<Invoice><xsl:apply-templates select="node()|@*"/></Invoice>
</xsl:template></xsl:stylesheet>
尝试在线搜索“XSLT命名空间” - 您引用的xmlns属性声明所有元素都在特定的命名空间中,并且您的XSLT需要反映这一点。 (我不知道确切的语法,所以不要打扰问题;我只是想指出一些问题。) – IMSoP
谢谢。我更新了XSLT:<?xml version =“1.0”encoding =“UTF-8”?> XSL:模板> 的 的 xsl:template> xsl:stylesheet>。现在它在发票后添加命名空间: –
user2157477
请... _不要发布代码在评论中,_ ***它是不可读的***。如果你对你的问题有更清楚的理解,[更新问题](http://stackoverflow.com/posts/32509696/edit)。 – Abel