使用XSLT将XML转换为XML转换目标XML上的属性

使用XSLT将XML转换为XML转换目标XML上的属性,xml,xslt,Xml,Xslt,我有这样的源XML- <FIXML xmlns="http://www.fixprotocol.org/FIXML-4-4" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Order ID="337228967" ID2="2867239" > <Instrmt ID="764635" Src="10

我有这样的源XML-

<FIXML xmlns="http://www.fixprotocol.org/FIXML-4-4" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Order ID="337228967" ID2="2867239" >
    <Instrmt ID="764635" Src="101" CFI="" SecTyp="Swap" SubTyp="Interest Rate Swap" >
    </Instrmt>
    <Stip Typ="TEXT" Val="ASSETALL" />
    <OrdQty Qty="250000" />
  </Order>
</FIXML>
当前XML如下所示:

<FIXML xmlns="http://www.fixprotocol.org/FIXML-4-4" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Order ID="337228967" ID2="2867239" >
    <Instrmt ID="764635" Src="101" CFI="" SecTyp="Swap" SubTyp="Multi-currency IRS" >
    </Instrmt>
    <Stip Typ="TEXT" Val="ASSETALL" />
    <OrdQty Qty="250000" />
  </Order>
</FIXML>

改造后,我希望它看起来像这样-

<FIXML xmlns="http://www.fixprotocol.org/FIXML-4-4" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Order ID="337228967" ID2="2867239" >
    <Instrmt ID="764635" Src="101" CFI="" SecTyp="Swap" SubTyp="Interest Rate Swap" >
    </Instrmt>
    <Stip Typ="TEXT" Val="ASSETALL" />
    <OrdQty Qty="250000" />
  </Order>
</FIXML>

基本上,当SubTyp=“多货币IRS”替换为SubTyp=“利率互换”时,我希望替换SubTyp文本。如果子类型为“多货币IRS”,则返回当前值

我试图告诉我们以下代码,但只看到与输入相同的输出。我没有看到价值的替代

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:f="fixprotocol.org/FIXML-4-4">
    <xsl:output method="xml" indent="yes" />

    <xsl:template match="f:Instrmt/@SubTyp">
        <xsl:choose>
        <xsl:when test="f:Instrmt/@SubTyp='Multi-currency IRS'">
            <xsl:text>Interest Rate Swap</xsl:text>
        </xsl:when>
    </xsl:choose>
    </xsl:template>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

利率互换

XSLT新手。任何帮助都将不胜感激。

以下是如何做到这一点:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:f="http://www.fixprotocol.org/FIXML-4-4">
    <xsl:output method="xml" indent="yes" />

    <xsl:template match="f:Instrmt/@SubTyp[.='Multi-currency IRS']">
        <xsl:attribute name="SubTyp">Interest Rate Swap</xsl:attribute>
    </xsl:template>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

利率互换
看到它在这里工作: