Reputation: 185
I have the following xml:
<LzMessage>
<LzPostExecution>
<LzMarketExecution>
<LzExecutionDetail>
<LzExecutionId>LNE12345</LzExecutionId>
<LzPostingVersion>1</LzPostingVersion>
<LzInstrumentId>INSTRID</LzInstrumentId>
<LzInstrumentName>INSTR NAME</LzInstrumentName>
<LzSide>B</LzSide>
<LzTradeType>A</LzTradeType>
<LzSettlementCurrency>DKK</LzSettlementCurrency>
<LzCounterpartyId>PTY</LzCounterpartyId>
<LzSettlementDate>2015070900000000</LzSettlementDate>
<LzCommissionBasis>BP</LzCommissionBasis>
<LzCommissionRate>0</LzCommissionRate>
<LzCommissionAmount>0</LzCommissionAmount>
<LzCommissionType>H</LzCommissionType>
<LzTradeDate>2015070700000000</LzTradeDate>
<LzOrderOriginatorId/>
<LzPostedBy>BOB</LzPostedBy>
<LzExecutionQuantity>95000</LzExecutionQuantity>
<LzExecutionPrice>107.99</LzExecutionPrice>
<LzPriceType>CLEAN</LzPriceType>
<LzFxRate>1</LzFxRate>
<LzContractSize>0</LzContractSize>
<LzGrossConsideration>103665.43</LzGrossConsideration>
<LzAccruedInterest>1074.93</LzAccruedInterest>
<LzCouponRate>1.75</LzCouponRate>
<LzOrderId>LNO12345</LzOrderId>
<LzExchangeId/>
<LzPaydownFactor>1</LzPaydownFactor>
<LzCurrentFaceQuantity>95000</LzCurrentFaceQuantity>
<LzPriceYieldEntry>P</LzPriceYieldEntry>
<LzExecutionYield>0.9365</LzExecutionYield>
<LzExecutionDatetime>2015070714185800</LzExecutionDatetime>
<LzRate>0</LzRate>
<LzReferenceRate>0</LzReferenceRate>
<LzPoints>0</LzPoints>
<LzUserData1/>
<LzFarExecutionQuantity>0</LzFarExecutionQuantity>
<LzFarExecutionQuantity2>0</LzFarExecutionQuantity2>
<LzSide2/>
<LzExecutionQuantity2>0</LzExecutionQuantity2>
<LzInstrument2Id/>
<LzSettlementDate2/>
<LzOrderType>1</LzOrderType>
<LzInstrumentIsin>DK0009923138</LzInstrumentIsin>
<LzInstrumentSedol>BMTRT97</LzInstrumentSedol>
<LzDealingDesk>DESK</LzDealingDesk>
<LzTransactionId>1234567</LzTransactionId>
<LzExecutionCurrency>DKK</LzExecutionCurrency>
<LzReferenceYield>0</LzReferenceYield>
<LzSpread>0</LzSpread>
<LzReferencePrice>0</LzReferencePrice>
<LzReferenceInstrumentId/>
<LzReferenceInstrumentName/>
</LzExecutionDetail>
<LzOrderDetail>
<LzOrderId>LNO12346</LzOrderId>
<LzPostingVersion/>
<LzTraderInstruction/>
<LzListId/>
<LzUserData1/>
<LzUserData2/>
<LzSourceId>SOURCE</LzSourceId>
<LzMinervaInstrumentType>3</LzMinervaInstrumentType>
<LzUserData11/>
<LzCurrencyQuotation>DKK</LzCurrencyQuotation>
<LzCurrencyQuotation2/>
<LzAddedBy>blah</LzAddedBy>
<LzAddedDatetime>2015070714180594</LzAddedDatetime>
<LzApprovedDatetime>2015070714180594</LzApprovedDatetime>
<LzApproverId/>
<LzDealerNote/>
<LzDealingDesk>DESK</LzDealingDesk>
<LzDrivingQuantity>1</LzDrivingQuantity>
<LzManagerId>BOB</LzManagerId>
<LzOriginalQuantity>95000</LzOriginalQuantity>
<LzWorkingTraders/>
</LzOrderDetail>
</LzMarketExecution>
<LzClientExecution>
<LzExecutionDetail>
<LzExecutionId>LNE12346</LzExecutionId>
<LzPostingVersion>1</LzPostingVersion>
<LzAccountId>ACC1</LzAccountId>
<LzAccountName>Account 1</LzAccountName>
<LzExecutionQuantity>95000</LzExecutionQuantity>
<LzExecutionPrice>107.99</LzExecutionPrice>
<LzGrossConsideration>103665.43</LzGrossConsideration>
<LzAccruedInterest>1074.93</LzAccruedInterest>
<LzFxRate>1</LzFxRate>
<LzPaydownFactor>1</LzPaydownFactor>
<LzCurrentFaceQuantity>95000</LzCurrentFaceQuantity>
<LzCommissionBasis>BP</LzCommissionBasis>
<LzCommissionRate>0</LzCommissionRate>
<LzCommissionAmount>0</LzCommissionAmount>
<LzSideCode>BO</LzSideCode>
<LzGiveUpCommissionCounterpartyId>PTY</LzGiveUpCommissionCounterpartyId>
<LzExposure>0</LzExposure>
<LzRate>0</LzRate>
<LzReferenceRate>0</LzReferenceRate>
<LzPoints>0</LzPoints>
<LzFarExecutionQuantity>0</LzFarExecutionQuantity>
<LzFarExecutionQuantity2>0</LzFarExecutionQuantity2>
<LzSide2/>
<LzExecutionQuantity2>0</LzExecutionQuantity2>
<LzSettlementDate2/>
<LzSettlementDate>2015070900000000</LzSettlementDate>
<LzSide>B</LzSide>
<LzOrderType>1</LzOrderType>
<lzmarketaccountname>ACC</lzmarketaccountname>
</LzExecutionDetail>
<LzAccountAllocation>
<LzAllocationDetail>
<LzExecutionNote/>
</LzAllocationDetail>
</LzAccountAllocation>
</LzClientExecution>
</LzPostExecution>
and the following xslt:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl acmex" xmlns:acmex="urn:schemas-acme-com:xslt-app-extensions">
<xsl:output method="xml" indent="yes"/>
<!--Copy whole message-->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="instrType" select="//LzMarketExecution/LzOrderDetail/LzMinervaInstrumentType"/>
<xsl:with-param name="clientAIValues">
<xsl:for-each select="//LzClientExecution/LzExecutionDetail">
<originalAI>
<xsl:value-of select="LzAccruedInterest"/>
</originalAI>
<tcAI>
<xsl:value-of select="acmex:DeriveValue('ClientTrade','AccruedInterest','',concat(LzExecutionId,'|',LzPostingVersion),'')"/>
</tcAI>
</xsl:for-each>
</xsl:with-param>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="//LzMarketExecution/LzExecutionDetail/LzAccruedInterest">
<xsl:param name="instrType"/>
<xsl:param name="clientAIValues"/>
<xsl:copy>
<xsl:choose>
<xsl:when test="$instrType='3'">
<xsl:value-of select="sum(msxsl:node-set($clientAIValues)/tcAI)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="//LzMarketExecution/LzExecutionDetail/LzGrossConsideration">
<xsl:param name="instrType"/>
<xsl:param name="clientAIValues"/>
<xsl:copy>
<xsl:choose>
<xsl:when test="$instrType='3'">
<xsl:value-of select=". - sum(msxsl:node-set($clientAIValues)/originalAI) + sum(msxsl:node-set($clientAIValues)/tcAI)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="//LzClientExecution/LzExecutionDetail/LzAccruedInterest">
<xsl:param name="instrType"/>
<xsl:copy>
<xsl:choose>
<xsl:when test="$instrType='3'">
<xsl:value-of select="acmex:DeriveValue('ClientTrade','AccruedInterest','',concat(../LzExecutionId,'|',../LzPostingVersion),'')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="//LzClientExecution/LzExecutionDetail/LzGrossConsideration">
<xsl:param name="instrType"/>
<xsl:copy>
<xsl:choose>
<xsl:when test="$instrType='3'">
<xsl:value-of select=". - ../LzAccruedInterest + acmex:DeriveValue('ClientTrade','AccruedInterest','',concat(../LzExecutionId,'|',../LzPostingVersion),'')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
When I apply this xslt though, the acmex:DeriveValue extension method gets called 110 times, whereas I would expect it to be called 3 times. Not sure why?
Upvotes: 0
Views: 40
Reputation: 167401
Well <xsl:template match="node()|@*">
matches any node for which you don't have any more specific template. And then inside of that template you apply templates to all attributes and all child nodes and compute that parameter value calling the extension function. Maybe you want to use a global parameter or variable where you compute the values once.
Upvotes: 1