FpML - 如何在复制整个 fpml 后替换名称空间中的文本?

FpML - how to replace a text in the namespace after copy the whole fpml?

我在复制 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>

基本上就是用'recordkeeping'

代替'transparency'

我试过像 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>

命名空间未被替换。

您有两个匹配相同模式的模板。这将产生错误或仅应用最后一个模板。

要显示结果,您只需执行以下操作:

<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>