简体   繁体   中英

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

I am facing trouble when try to replace the namespace after copy the fpml. I need to replace

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

for

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

Basically is replace 'transparency' by 'recordkeeping'

I have tried follow the previous question like XML replacement with XSL but without success for my case.

What I do is:

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

The namespace isn't being replaced.

You have two templates matching the same pattern. This will either produce an error or only the last template will be applied.

To get the result shown, you could do simply:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM