0

I have source XML that looks like this -

Currently XML looks as follows:

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

After transformation I want it to look like this -

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

Basically, I am looking to replace SubTyp text when SubTyp = "Multi-currency IRS" replace to SubTyp = "Interest Rate Swap". If SubType <> "Multi-currency IRS", return current value.

I am trying to us the following code but only see output same as input. I am not seeing the value replacement

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

New to XSLT. Any help would be much appreciated.

1 Answer 1

1

Here's how it can be done :

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

See it working here : https://xsltfiddle.liberty-development.net/ehVZvvU

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.