Node.js 用另一个名称空间替换一个名称空间
在下面的输入XML中,我得到了ns1和ns2前缀。 在输出中,名称空间ns1应替换为dh,名称空间ns2应替换为sk 有人能帮忙吗Node.js 用另一个名称空间替换一个名称空间,node.js,xml,xslt,xpath,xml-namespaces,Node.js,Xml,Xslt,Xpath,Xml Namespaces,在下面的输入XML中,我得到了ns1和ns2前缀。 在输出中,名称空间ns1应替换为dh,名称空间ns2应替换为sk 有人能帮忙吗 <?xml version="1.0" encoding="UTF-8" ?> <sh:sampleDocument schemaVersion="" creationDate=""xmlns:sh="htpp://sample1.com"> <sampleHeader> <ns1:sampledo
<?xml version="1.0" encoding="UTF-8" ?>
<sh:sampleDocument schemaVersion="" creationDate=""xmlns:sh="htpp://sample1.com">
<sampleHeader>
<ns1:sampledocumentheader xmlns:ns1="htpp://sample2.com">
<ns1:HeaderVersion />
<ns1:ContactInformation>
<ns1:Contact />
<ns1:EmailAddress />
<ns1:FaxNumber />
<ns1:TelephoneNumber />
<ns1:ContactTypeIdentifier />
</ns1:ContactInformation>
</ns1:sampledocumentheader>
</sampleHeader>
<sampleBody>
<sampleList>
<sampleEvent>
<Time />
<action />
<ns2:sampleExtension xmlns:ns2="htpp://sample3.com">
<ns2:Value />
<ns2:Number />
</ns2:sampleExtension>
</sampleEvent>
</sampleList>
</sampleBody>
</sh:sampleDocument>
应该没有必要这样做。名称空间前缀的选择完全是任意的。如果目标应用程序需要使用特定的前缀,那么需要修复的是目标应用程序,而不是XML 无论如何,请尝试: XSLT1.0
这样做的目的是什么?前缀没有任何意义,可以完全任意;真正重要的是它绑定到的URI。接收方应用程序需要这些前缀来接受数据。我也和他们讨论过,但他们想要这些前缀。所以他们太懒了,不想做对,结果你有额外的工作要做?
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="htpp://sample2.com"
xmlns:ns2="htpp://sample3.com"
exclude-result-prefixes="ns1 ns2">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ns1:*">
<xsl:element name="dh:{local-name()}" namespace="{namespace-uri()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="ns2:*">
<xsl:element name="sk:{local-name()}" namespace="{namespace-uri()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>