Link to home
Start Free TrialLog in
Avatar of shukla1_alok
shukla1_alok

asked on

XSL Style Sheet Question

Hello,

I am trying to extract data from the XML via an XSL seems I am not able to extract the data though looked at the syntax documentation but not able to find anything wrong with my XSL which is also given below the sample XML.

Your help would be appreciated.

Thanks,
Alok

Sample XML

<?xml version="1.0" encoding="UTF-8"?>
<SWBML xmlns="http://www.fpml.org/2005/FpML-4-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4-2" xsi:schemaLocation="http://www.fpml.org/2005/FpML-4-2 swbml-ird-main-4-2.xsd">
      <swbHeader>
            <swbBrokerTradeId>ALOK4_1108299</swbBrokerTradeId>
            <swbBrokerTradeVersionId>15</swbBrokerTradeVersionId>
            <swbTradeSource>Voice</swbTradeSource>
            <swbRecipient id="_recip_1_">
                  <partyReference href="partyA"/>
            </swbRecipient>
            <swbRecipient id="_recip_2_">
                  <partyReference href="partyB"/>
            </swbRecipient>
      </swbHeader>
      <swbStructuredTradeDetails>
            <swbProductType>Single Currency Basis Swap</swbProductType>
            <FpML xmlns="http://www.fpml.org/2005/FpML-4-2" version="4-2" xsi:type="DataDocument">
                  <trade id="ALOK4_1108299">
                        <tradeHeader>
                              <partyTradeIdentifier>
                                    <partyReference href="partyA"/>
                                    <tradeId tradeIdScheme="http://www.swapswire.com/spec/2001/trade-id-1-0">ALOK4_1108299</tradeId>
                              </partyTradeIdentifier>
                              <partyTradeIdentifier>
                                    <partyReference href="partyB"/>
                                    <tradeId tradeIdScheme="http://www.swapswire.com/spec/2001/trade-id-1-0">ALOK4_1108299</tradeId>
                              </partyTradeIdentifier>
                              <tradeDate>2009-07-07</tradeDate>
                        </tradeHeader>
                        <swap>
                              <swapStream id="floatingLeg">
                                    <payerPartyReference href="partyA"/>
                                    <receiverPartyReference href="partyB"/>
                                    <calculationPeriodDates id="floatingLegCalcPeriodDates">
                                          <effectiveDate>
                                                <unadjustedDate>2009-07-09</unadjustedDate>
                                                <dateAdjustments>
                                                      <businessDayConvention>NONE</businessDayConvention>
                                                </dateAdjustments>
                                          </effectiveDate>
                                          <terminationDate>
                                                <unadjustedDate>2010-07-09</unadjustedDate>
                                                <dateAdjustments>
                                                      <businessDayConvention>MODFOLLOWING</businessDayConvention>
                                                      <businessCenters>
                                                            <businessCenter>GBLO</businessCenter>
                                                            <businessCenter>USNY</businessCenter>
                                                      </businessCenters>
                                                </dateAdjustments>
                                          </terminationDate>
                                          <calculationPeriodDatesAdjustments>
                                                <businessDayConvention>MODFOLLOWING</businessDayConvention>
                                                <businessCenters>
                                                      <businessCenter>GBLO</businessCenter>
                                                      <businessCenter>USNY</businessCenter>
                                                </businessCenters>
                                          </calculationPeriodDatesAdjustments>
                                          <calculationPeriodFrequency>
                                                <periodMultiplier>1</periodMultiplier>
                                                <period>M</period>
                                                <rollConvention>9</rollConvention>
                                          </calculationPeriodFrequency>
                                    </calculationPeriodDates>
                                    <paymentDates>
                                          <calculationPeriodDatesReference href="floatingLegCalcPeriodDates"/>
                                          <paymentFrequency>
                                                <periodMultiplier>1</periodMultiplier>
                                                <period>M</period>
                                          </paymentFrequency>
                                          <payRelativeTo>CalculationPeriodEndDate</payRelativeTo>
                                          <paymentDatesAdjustments>
                                                <businessDayConvention>MODFOLLOWING</businessDayConvention>
                                                <businessCenters>
                                                      <businessCenter>GBLO</businessCenter>
                                                      <businessCenter>USNY</businessCenter>
                                                </businessCenters>
                                          </paymentDatesAdjustments>
                                    </paymentDates>
                                    <resetDates id="floatingLegResetDates">
                                          <calculationPeriodDatesReference href="floatingLegCalcPeriodDates"/>
                                          <resetRelativeTo>CalculationPeriodStartDate</resetRelativeTo>
                                          <fixingDates>
                                                <periodMultiplier>-2</periodMultiplier>
                                                <period>D</period>
                                                <dayType>Business</dayType>
                                                <businessDayConvention>NONE</businessDayConvention>
                                                <businessCenters>
                                                      <businessCenter>GBLO</businessCenter>
                                                </businessCenters>
                                                <dateRelativeTo href="floatingLegResetDates"/>
                                          </fixingDates>
                                          <resetFrequency>
                                                <periodMultiplier>1</periodMultiplier>
                                                <period>M</period>
                                          </resetFrequency>
                                          <resetDatesAdjustments>
                                                <businessDayConvention>MODFOLLOWING</businessDayConvention>
                                                <businessCenters>
                                                      <businessCenter>GBLO</businessCenter>
                                                      <businessCenter>USNY</businessCenter>
                                                </businessCenters>
                                          </resetDatesAdjustments>
                                    </resetDates>
                                    <calculationPeriodAmount>
                                          <calculation>
                                                <notionalSchedule>
                                                      <notionalStepSchedule>
                                                            <initialValue>50000000</initialValue>
                                                            <currency>USD</currency>
                                                      </notionalStepSchedule>
                                                </notionalSchedule>
                                                <floatingRateCalculation>
                                                      <floatingRateIndex>USD-LIBOR-BBA</floatingRateIndex>
                                                      <indexTenor>
                                                            <periodMultiplier>1</periodMultiplier>
                                                            <period>M</period>
                                                      </indexTenor>
                                                      <spreadSchedule>
                                                            <initialValue>0.0007</initialValue>
                                                      </spreadSchedule>
                                                      <initialRate>0.06</initialRate>
                                                </floatingRateCalculation>
                                                <dayCountFraction>ACT/360</dayCountFraction>
                                          </calculation>
                                    </calculationPeriodAmount>
                              </swapStream>
                              <swapStream id="floatingLeg2">
                                    <payerPartyReference href="partyB"/>
                                    <receiverPartyReference href="partyA"/>
                                    <calculationPeriodDates id="floatingLeg2CalcPeriodDates">
                                          <effectiveDate>
                                                <unadjustedDate>2009-07-09</unadjustedDate>
                                                <dateAdjustments>
                                                      <businessDayConvention>NONE</businessDayConvention>
                                                </dateAdjustments>
                                          </effectiveDate>
                                          <terminationDate>
                                                <unadjustedDate>2010-07-09</unadjustedDate>
                                                <dateAdjustments>
                                                      <businessDayConvention>MODFOLLOWING</businessDayConvention>
                                                      <businessCenters>
                                                            <businessCenter>GBLO</businessCenter>
                                                            <businessCenter>USNY</businessCenter>
                                                      </businessCenters>
                                                </dateAdjustments>
                                          </terminationDate>
                                          <calculationPeriodDatesAdjustments>
                                                <businessDayConvention>MODFOLLOWING</businessDayConvention>
                                                <businessCenters>
                                                      <businessCenter>GBLO</businessCenter>
                                                      <businessCenter>USNY</businessCenter>
                                                </businessCenters>
                                          </calculationPeriodDatesAdjustments>
                                          <calculationPeriodFrequency>
                                                <periodMultiplier>3</periodMultiplier>
                                                <period>M</period>
                                                <rollConvention>9</rollConvention>
                                          </calculationPeriodFrequency>
                                    </calculationPeriodDates>
                                    <paymentDates>
                                          <calculationPeriodDatesReference href="floatingLeg2CalcPeriodDates"/>
                                          <paymentFrequency>
                                                <periodMultiplier>3</periodMultiplier>
                                                <period>M</period>
                                          </paymentFrequency>
                                          <payRelativeTo>CalculationPeriodEndDate</payRelativeTo>
                                          <paymentDatesAdjustments>
                                                <businessDayConvention>MODFOLLOWING</businessDayConvention>
                                                <businessCenters>
                                                      <businessCenter>GBLO</businessCenter>
                                                      <businessCenter>USNY</businessCenter>
                                                </businessCenters>
                                          </paymentDatesAdjustments>
                                    </paymentDates>
                                    <resetDates id="floatingLeg2ResetDates">
                                          <calculationPeriodDatesReference href="floatingLeg2CalcPeriodDates"/>
                                          <resetRelativeTo>CalculationPeriodStartDate</resetRelativeTo>
                                          <fixingDates>
                                                <periodMultiplier>-2</periodMultiplier>
                                                <period>D</period>
                                                <dayType>Business</dayType>
                                                <businessDayConvention>NONE</businessDayConvention>
                                                <businessCenters>
                                                      <businessCenter>GBLO</businessCenter>
                                                </businessCenters>
                                                <dateRelativeTo href="floatingLeg2ResetDates"/>
                                          </fixingDates>
                                          <resetFrequency>
                                                <periodMultiplier>3</periodMultiplier>
                                                <period>M</period>
                                          </resetFrequency>
                                          <resetDatesAdjustments>
                                                <businessDayConvention>MODFOLLOWING</businessDayConvention>
                                                <businessCenters>
                                                      <businessCenter>GBLO</businessCenter>
                                                      <businessCenter>USNY</businessCenter>
                                                </businessCenters>
                                          </resetDatesAdjustments>
                                    </resetDates>
                                    <calculationPeriodAmount>
                                          <calculation>
                                                <notionalSchedule>
                                                      <notionalStepSchedule>
                                                            <initialValue>50000000</initialValue>
                                                            <currency>USD</currency>
                                                      </notionalStepSchedule>
                                                </notionalSchedule>
                                                <floatingRateCalculation>
                                                      <floatingRateIndex>USD-LIBOR-BBA</floatingRateIndex>
                                                      <indexTenor>
                                                            <periodMultiplier>3</periodMultiplier>
                                                            <period>M</period>
                                                      </indexTenor>
                                                      <initialRate>0.06</initialRate>
                                                </floatingRateCalculation>
                                                <dayCountFraction>ACT/360</dayCountFraction>
                                          </calculation>
                                    </calculationPeriodAmount>
                              </swapStream>
                        </swap>
                        <otherPartyPayment>
                              <payerPartyReference href="partyA"/>
                              <receiverPartyReference href="broker1"/>
                              <paymentAmount>
                                    <currency>USD</currency>
                                    <amount>0.0</amount>
                              </paymentAmount>
                        </otherPartyPayment>
                        <otherPartyPayment>
                              <payerPartyReference href="partyB"/>
                              <receiverPartyReference href="broker1"/>
                              <paymentAmount>
                                    <currency>USD</currency>
                                    <amount>0.0</amount>
                              </paymentAmount>
                        </otherPartyPayment>
                        <documentation>
                              <masterAgreement>
                                    <masterAgreementType masterAgreementTypeScheme="http://www.swapswire.com/spec/2001/master-agreement-type-1-0">ISDA</masterAgreementType>
                              </masterAgreement>
                              <contractualDefinitions>ISDA2006</contractualDefinitions>
                        </documentation>
                  </trade>
                  <party id="partyA">
                        <partyId>BB1TULLLE1</partyId>
                  </party>
                  <party id="partyB">
                        <partyId>BB2TULLLE1</partyId>
                  </party>
                  <party id="broker1">
                        <partyId>TULL_NY</partyId>
                  </party>
            </FpML>
            <swbExtendedTradeDetails>
                  <swbProductTerm>
                        <periodMultiplier>1</periodMultiplier>
                        <period>Y</period>
                  </swbProductTerm>
                  <swbMessageText>Brokerage to be invoiced directly with Tullett.</swbMessageText>
            </swbExtendedTradeDetails>
      </swbStructuredTradeDetails>
</SWBML>

Sample XSL

<!--<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">-->
            <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fpml="http://www.fpml.org/2005/FpML-4-2"
xmlns:fo="http://www.w3.org/1999/XSL/Format" >
    <xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/">
        <xsl:text disable-output-escaping="yes">TradeVersion: </xsl:text>
        <xsl:value-of select="SWBML/swbHeader/swbBrokerTradeVersionId"/>
        <xsl:text>&#xD;</xsl:text>
          <!--<xsl:text disable-output-escaping="yes">swbRecipient Called. </xsl:text>-->
        <xsl:apply-templates select="/SWBML/swbHeader/swbRecipient"/>
          <!--<xsl:text disable-output-escaping="yes">Party Called. </xsl:text>-->
          <xsl:apply-templates select="/SWBML/swbStructuredTradeDetails/FpML/party"/>
    </xsl:template>

    <xsl:template match="swbRecipient">
        <xsl:param name="href" select="./partyReference/@href"/>
        <xsl:param name="dealType" select="/SWBML/swbStructuredTradeDetails/swbProductType"/>
        <xsl:param name="definingleg" select="'fixedLeg'"/>
        <xsl:param name="definingpath" select="/SWBML/swbStructuredTradeDetails/FpML/trade/swap/swapStream"/>
          <!--<xsl:text disable-output-escaping="yes">swbRecipient In. </xsl:text>-->
        <xsl:choose>
              <xsl:when test="$dealType = 'Single Currency Basis Swap'">
                  <xsl:call-template name="getRecipientInformation">
                      <xsl:with-param name="href" select="$href"/>
                      <xsl:with-param name="payer" select="/SWBML/swbStructuredTradeDetails/FpML/trade/swap/swapStreams/swapStream[@id='floatingLeg']/payerPartyReference"/>
                      <xsl:with-param name="receiver" select="/SWBML/swbStructuredTradeDetails/FpML/trade/swap/swapStreams/swapStream[@id='floatingLeg']/receiverPartyReference"/>
                  </xsl:call-template>
              </xsl:when>

            <xsl:otherwise>
                <xsl:call-template name="getRecipientInformation">
                    <xsl:with-param name="href" select="$href"/>
                    <xsl:with-param name="payer" select="/SWBML/swbStructuredTradeDetails/FpML/trade/swap/swapStream[@id=$definingleg]/payerPartyReference"/>
                    <xsl:with-param name="receiver" select="/SWBML/swbStructuredTradeDetails/FpML/trade/swap/swapStream[@id=$definingleg]/receiverPartyReference"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="getRecipientInformation">
        <xsl:param name="href"/>
        <xsl:param name="payer"/>
        <xsl:param name="receiver"/>
        <xsl:choose>
            <xsl:when test="$payer/@href = $href">
                <xsl:text disable-output-escaping="yes">PayerRecipTag: </xsl:text>
                <xsl:value-of select="@id"/>
            </xsl:when>
            <xsl:when test="$receiver/@href = $href">
                <xsl:text disable-output-escaping="yes">ReceiverRecipTag: </xsl:text>
                <xsl:value-of select="@id"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text disable-output-escaping="yes"></xsl:text>
                <xsl:value-of select="@id"/>
            </xsl:otherwise>
        </xsl:choose>
        <xsl:text>&#xD;</xsl:text>
    </xsl:template>

    <xsl:template match="party">
        <xsl:param name="href" select="./@id"/>
        <xsl:param name="dealType" select="/SWBML/swbStructuredTradeDetails/swbProductType"/>
        <xsl:param name="definingleg" select="'floatingLeg'"/>
        <xsl:param name="definingpath" select="/SWBML/swbStructuredTradeDetails/FpML/trade/swap/swapStream"/>
        <xsl:choose>
            <!--<xsl:when test="$dealType = 'Single Currency Basis Swap'">-->
                <!--<xsl:call-template name="getFraSwiftInformation">-->
                    <!--<xsl:with-param name="href" select="$href"/>-->
                <!--</xsl:call-template>-->
            <!--</xsl:when>-->

            <xsl:when test="$dealType = 'CDS'">
                <xsl:call-template name="getCDSSwiftInformation">
                    <xsl:with-param name="href" select="$href"/>
                </xsl:call-template>
            </xsl:when>

            <xsl:otherwise>
                <xsl:choose>
                    <xsl:when test="$definingpath[@id=$definingleg]/payerPartyReference/@href = concat('#', $href)">
                        <xsl:call-template name="swiftStrip">
                            <xsl:with-param name="swiftId" select="./partyId/text()"/>
                            <xsl:with-param name="payrec">
                                <xsl:text disable-output-escaping="yes">PayerSwiftcode: </xsl:text>
                            </xsl:with-param>
                            <xsl:with-param name="sspSide">
                                <xsl:text disable-output-escaping="yes">P</xsl:text>
                            </xsl:with-param>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:when test="$definingpath[@id=$definingleg]/receiverPartyReference/@href = concat('#', $href)">
                        <xsl:call-template name="swiftStrip">
                            <xsl:with-param name="swiftId" select="./partyId/text()"/>
                            <xsl:with-param name="payrec">
                                <xsl:text disable-output-escaping="yes">ReceiverSwiftcode: </xsl:text>
                            </xsl:with-param>
                            <xsl:with-param name="sspSide">
                                <xsl:text disable-output-escaping="yes">R</xsl:text>
                            </xsl:with-param>
                        </xsl:call-template>
                    </xsl:when>
                </xsl:choose>
                <xsl:text>&#xD;</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="getFraSwiftInformation">
        <xsl:param name="href"/>
        <xsl:param name="definingpath" select="/SWBML/swbStructuredTradeDetails/FpML/trade/fra"/>
        <xsl:choose>
            <xsl:when test="$definingpath/buyerPartyReference/@href = concat('#', $href)">
                <xsl:call-template name="swiftStrip">
                    <xsl:with-param name="swiftId" select="./partyId/text()"/>
                    <xsl:with-param name="payrec">
                        <xsl:text disable-output-escaping="yes">PayerSwiftcode: </xsl:text>
                    </xsl:with-param>
                    <xsl:with-param name="sspSide">
                        <xsl:text disable-output-escaping="yes">P</xsl:text>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$definingpath/sellerPartyReference/@href = concat('#', $href)">
                <xsl:call-template name="swiftStrip">
                    <xsl:with-param name="swiftId" select="./partyId/text()"/>
                    <xsl:with-param name="payrec">
                        <xsl:text disable-output-escaping="yes">ReceiverSwiftcode: </xsl:text>
                    </xsl:with-param>
                    <xsl:with-param name="sspSide">
                        <xsl:text disable-output-escaping="yes">R</xsl:text>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:when>
        </xsl:choose>
        <xsl:text>&#xD;</xsl:text>
    </xsl:template>

    <xsl:template name="getCDSSwiftInformation">
        <xsl:param name="href"/>
        <xsl:param name="definingpath" select="/SWBML/swbStructuredTradeDetails/FpML/trade/creditDefaultSwap/generalTerms"/>
        <xsl:choose>
            <xsl:when test="$definingpath/buyerPartyReference/@href = $href">
                <xsl:call-template name="swiftStrip">
                    <xsl:with-param name="swiftId" select="./partyId/text()"/>
                    <xsl:with-param name="payrec">
                        <xsl:text disable-output-escaping="yes">PayerSwiftcode: </xsl:text>
                    </xsl:with-param>
                    <xsl:with-param name="sspSide">
                        <xsl:text disable-output-escaping="yes">P</xsl:text>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$definingpath/sellerPartyReference/@href = $href">
                <xsl:call-template name="swiftStrip">
                    <xsl:with-param name="swiftId" select="./partyId/text()"/>
                    <xsl:with-param name="payrec">
                        <xsl:text disable-output-escaping="yes">ReceiverSwiftcode: </xsl:text>
                    </xsl:with-param>
                    <xsl:with-param name="sspSide">
                        <xsl:text disable-output-escaping="yes">R</xsl:text>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:when>
        </xsl:choose>
        <xsl:text>&#xD;</xsl:text>
    </xsl:template>

    <xsl:template name="swiftStrip">
        <xsl:param name="swiftId"/>
        <xsl:param name="payrec"/>
        <xsl:param name="sspSide"/>
        <xsl:text disable-output-escaping="yes"></xsl:text>
        <xsl:value-of select="$payrec"/>
        <xsl:choose>

            <xsl:when test="string-length(substring-before($swiftId, 'XXX_SSP'))  > 0">
                <xsl:value-of select="substring-before($swiftId, 'XXX_SSP')"/>
                <xsl:text>&#xD;</xsl:text>

                <xsl:text disable-output-escaping="yes">SspSide: </xsl:text>
                <xsl:value-of select="$sspSide"/>
                <xsl:text>&#xD;</xsl:text>

            </xsl:when>

            <xsl:when test="string-length(substring-before($swiftId, '_SSP'))  > 0">
                <xsl:value-of select="substring-before($swiftId, '_SSP')"/>
                <xsl:text>&#xD;</xsl:text>

                <xsl:text disable-output-escaping="yes">SspSide: </xsl:text>
                <xsl:value-of select="$sspSide"/>
                <xsl:text>&#xD;</xsl:text>

            </xsl:when>

            <xsl:otherwise>
                <xsl:value-of select="$swiftId"/>
            </xsl:otherwise>

        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>
Avatar of cdall
cdall

Could you please specify what you are trying to extract excactly and maybe boil down the XML example to suggest a structure instead of giving this very long document?
Avatar of shukla1_alok

ASKER

Trying to Extract following node values from the XML

<swbBrokerTradeVersionId>15</swbBrokerTradeVersionId> from the following XML Section

<swbHeader>
      <swbBrokerTradeId>ALOK4_1108299</swbBrokerTradeId>
      <swbBrokerTradeVersionId>15</swbBrokerTradeVersionId>
      <swbTradeSource>Voice</swbTradeSource>
      <swbRecipient id="_recip_1_">
            <partyReference href="partyA"/>
      </swbRecipient>
      <swbRecipient id="_recip_2_">
            <partyReference href="partyB"/>
            </swbRecipient>
</swbHeader>

Trying to apply the following templates to extract the relevant data
Regarding the participants with the help below-mentioned particiapants.

<xsl:apply-templates select="/SWBML/swbHeader/swbRecipient"/>
<xsl:apply-templates select="/SWBML/swbStructuredTradeDetails/FpML/party"/>
Avatar of Gertone (Geert Bormans)
You have to realise that all elements are in a namespace
because of the xmlns attribute
<SWBML xmlns="http://www.fpml.org/2005/FpML-4-2"
So you will have to address the elements in this namespace
Yo can not do that by setting this namespace to the default namespace in your stylesheet, so you will need one with a prefix.
You did that right in your stylesheet header
xmlns:fpml="http://www.fpml.org/2005/FpML-4-2"
But this means that you need to prefix every element in every single XPath expression in your stylesheet

<xsl:apply-templates select="/fpml:SWBML/fpml:swbHeader/fpml:swbRecipient"/>
it is an ugly task, but there is no other way in XSLT1
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Note that in XSLT2, you can set the default namespace for all XPaths in the stylesheet, that takes away a lot of work from this example
Perfecto,  I did the same thing for something else but simply didn't pay attention. But thanks for your help.