Frage

Using the following input XML, my goal is to initially select portfolios/portfolio node, then the <tradeContribution> child nodes - specifically contributions/tradeContribution .

These tradeContribution nodes will then be transformed into the <trade> nodes in the xml output shown below.

My xml output and XSLT code follows below...

      <outBound>
<requestReceivedTime>2014-05-15 15:20:42.279</requestReceivedTime>
<responseSentTime>2014-05-15 15:20:42.338</responseSentTime>
<body>
   <portfolios>
        <portfolio id="36" nodeDate="2014-05-06">
            <query>
                <firstTerm>
                    <date>2014-05-06</date>
                </firstTerm>
                <lastTerm>
                    <date>2014-05-06</date>
                </lastTerm>
            </query>
            <exposure>492691.50878619519</exposure>
            <contributions>
                <tradeContribution contextId="0" contribution="267624.242492124" dealId="IRSW-TRADE-00011" desc="IRSW-FIX-FLOAT" order="0" sysId="1" tradeId="IRSW-TRADE-00011">
                    <hideTrade>false</hideTrade>
                    <readOnly>false</readOnly>
                </tradeContribution>
                <tradeContribution contextId="7" contribution="225067.26629407122" dealId="IRSW-TRADE-00020" desc="IRSW-FIX-FLOAT" order="1" sysId="2" tradeId="IRSW-TRADE-00020">
                    <hideTrade>false</hideTrade>
                    <readOnly>false</readOnly>
                </tradeContribution>
            </contributions>
            <nodeAnalysis id="HSVaR 5D 100 ES">
                <method>INTERPOLATED_EXPECTED_SHORTFALL</method>
                <exposure>true</exposure>
                <percentile>100</percentile>
            </nodeAnalysis>
        </portfolio>
    </portfolios>
  </body>
 </outBound>

My desired XML output is:

  <?xml version="1.0" ?>
  <collection>
    <trade>
     <legal_id>36</legal_id>
     <tradeRef>IRS-RRT-002</tradeRef>
     <system>MY SYSTEM IRS</system>
     <indepMtmValuation>111111</indepMtmValuation>
     <indepMtmValuationCcy>USD</indepMtmValuationCcy>
     <principalDealLevelUpfront>TRUE</principalDealLevelUpfront>
     <principalDealLevelAmount>14</principalDealLevelAmount>
     <principalDealLevelCurrency>USD</principalDealLevelCurrency>
     <principalDealLevelType>Independent Amount</principalDealLevelType>
     <operation>U</operation>
    </trade>    
    <trade>
     <legal_id>36</legal_id>
     <system>MY SYSTEM CDS</system>
     <tradeRef>CDS-RRT-008</tradeRef>
     <mtmValuation>222222</mtmValuation>
     <mtmValuationDate>2013-09-11</mtmValuationDate>
     <mtmValuationLocalSysCcy>USD</mtmValuationLocalSysCcy>
     <counterpartyDealLevelUpfront>TRUE</counterpartyDealLevelUpfront>
     <counterpartyDealLevelAmount>15</counterpartyDealLevelAmount>
     <counterpartyDealLevelCurrency>JPY</counterpartyDealLevelCurrency>
     <counterpartyDealLevelType>Independent Amount</counterpartyDealLevelType>      
   </trade>
 </collection>

The XSLT I have so far is as follows; however, I have a problem:

1) Trying to find the best way to pull the value of attribute "id", which is part of <portfolio id="36" nodeDate="2014-05-06"> . I need to output it to <legal_id>, but this here is NOT working:

  <legal_id><xsl:value-of select="../portfolio[@id]"/></legal_id>

Your advice would be greatly appreciate in helping to properly construct my XSLT to produce the desired XML output shown above:

My XSLT code thus far:

  <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xs xd"
version="1.0">

<!-- Variable declaration -->
<xsl:variable name="hsVar1D" select="'1D (99%)'"></xsl:variable>
<xsl:variable name="hsVar5D" select="'HSVaR 5D 100 ES'"></xsl:variable>

<xsl:template match="/*">
    <collection>
        <xsl:apply-templates select="/outbound/body/portfolios/portfolio[descendant::nodeAnalysis[@id[contains(.,$hsVar5D)]]]" />            
    </collection>
</xsl:template>
<xsl:template match="*">
    <xsl:apply-templates select="contributions/tradeContribution"/>
</xsl:template>
<xsl:template match="contributions/tradeContribution">
    <trade>
        <!-- QUESTION: For <legal_id> what is the best way to select the @id attrib from the ancestor node <portfolio> -->
        <legal_id><xsl:value-of select="@id"/></legal_id>
        <legal_id222><xsl:value-of select="../portfolio[@id]"/></legal_id222>
        <tradeRef>IRS-RRT-002</tradeRef>
        <system>MY SYSTEM IRS</system>
        <indepMtmValuation>111111</indepMtmValuation>
        <indepMtmValuationCcy>USD</indepMtmValuationCcy>
        <principalDealLevelUpfront>TRUE</principalDealLevelUpfront>
        <principalDealLevelAmount><xsl:value-of select="exposure"></xsl:value-of></principalDealLevelAmount>
        <principalDealLevelCurrency>USD</principalDealLevelCurrency>
        <principalDealLevelType>Independent Amount</principalDealLevelType>
        <operation>U</operation>
    </trade>
 </xsl:template>

War es hilfreich?

Lösung

Try it this way:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<!-- Variable declaration -->
<xsl:variable name="hsVar1D" select="'1D (99%)'"></xsl:variable>
<xsl:variable name="hsVar5D" select="'HSVaR 5D 100 ES'"></xsl:variable>

<xsl:template match="/">
    <collection>
        <xsl:apply-templates select="outBound/body/portfolios/portfolio[nodeAnalysis[contains(@id,$hsVar5D)]]/contributions/tradeContribution" />            
    </collection>
</xsl:template>

<xsl:template match="tradeContribution">
    <trade>
        <legal_id>
            <xsl:value-of select="../../../portfolio/@id"/>
        </legal_id>
        <tradeRef>IRS-RRT-002</tradeRef>
        <system>RAZOR IRS</system>
        <indepMtmValuation>111111</indepMtmValuation>
        <indepMtmValuationCcy>USD</indepMtmValuationCcy>
        <principalDealLevelUpfront>TRUE</principalDealLevelUpfront>
        <principalDealLevelAmount>
            <xsl:value-of select="../../nodeAnalysis/exposure"/>
        </principalDealLevelAmount>
        <principalDealLevelCurrency>USD</principalDealLevelCurrency>
        <principalDealLevelType>Independent Amount</principalDealLevelType>
        <operation>U</operation>
    </trade>
</xsl:template>

</xsl:stylesheet>

--
Note outBound vs. razorOutbound

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top