在复制fpml之后尝试替换名称空间时,我遇到了麻烦。我需要更换
<nonpublicExecutionReport xmlns="http://www.fpml.org/FpML-5/transparency" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.fpml.org/FpML-5/transparency file:///C:/APPS/Resources/xmls/SDR/transparency/fpml-main-5-5.xsd" fpmlVersion="5-5">
<A/>
<B/>
</nonpublicExecutionReport>
为
<nonpublicExecutionReport fpmlVersion="5-5" xsi:schemaLocation="http://www.fpml.org/FpML-5/recordkeeping /../xmls/SDR/recordkeeping/fpml-main-5-5.xsd" xmlns="http://www.fpml.org/FpML-5/recordkeeping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<A/>
<B/>
</nonpublicExecutionReport>
基本上就是把“透明”换成“记录”
我像XML replacement with XSL一样尝试了前面的问题,但在我的案例中没有成功。
我所做的是:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" mlns:fpml="http://www.fpml.org/FpML-5/transparency">
<!-- Copy XML source -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- Remove transparency from the layout-->
<xsl:template match="fpml:*">
<!-- Update this tag -->
<xsl:element name="{local-name()}">
<nonpublicExecutionReport xmlns="http://www.fpml.org/FpML-5/reportkeeping" fpmlVersion="5-5" xsi:schemaLocation="http://www.fpml.org/FpML-5/recordkeeping/../xmls/SDR/recordkeeping/fpml-main-5-5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:apply-templates select="node()"/>
</nonpublicExecutionReport>
</xsl:element>
</xsl:template>
<xsl:template match="fpml:*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
命名空间未被替换。
发布于 2021-01-28 00:05:03
您有两个模板匹配相同的模式。这将产生一个错误,或者只应用最后一个模板。
要获得显示的结果,您可以简单地执行以下操作:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fpml="http://www.fpml.org/FpML-5/transparency">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="fpml:*">
<xsl:element name="{local-name()}" namespace="http://www.fpml.org/FpML-5/recordkeeping">
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
https://stackoverflow.com/questions/65917561
复制相似问题