简体   繁体   English

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

[英]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.复制 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.我尝试按照前面的问题进行操作,例如用 XSL 替换 XML,但我的情况没有成功。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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