Using position()
Hi frns,
I am first time using the function position().Please help me in resolving this.
input xml:
<LMPRequests>
<LMPRequest>
<LMPMessage>Details
<Section>Criteria
<Row>
<REGION_CODE>524002</REGION_CODE>
<STATUS>Y</STATUS>
<FUND_AMOUNT1>25.00</FUND_AMOUNT1>
<FUND_AMOUNT2>125.00</FUND_AMOUNT2>
<FUND_AMOUNT3>125.00</FUND_AMOUNT3>
<FUND_CODE1>A123</FUND_CODE1>
<FUND_CODE2>CB12</FUND_CODE2>
<FUND_CODE3>jk12</FUND_CODE3>
<UNIT_TYPE1>A</UNIT_TYPE1>
<UNIT_TYPE2>D</UNIT_TYPE2> <UNIT_TYPE3>C</UNIT_TYPE3>
</Row>
</Section>
</LMPMessage>
</LMPRequest>
</LMPRequests>
outputxml :
<?xml version="1.0" encoding="UTF-8"?>
<CreateClient xmlns="http://ufus.com/us/webservices">
<criteria>
<regioncode>524002</regioncode>
<Status>Y</Status>
<Assets>
<RegularInvestmentAsset>
<FUND_CODE>A123</FUND_CODE>
<UNIT_TYPE>A</UNIT_TYPE>
<FUND_AMOUNT>25.00</FUND_AMOUNT>
</RegularInvestmentAsset>
<RegularInvestmentAsset>
<FUND_CODE>CB12</FUND_CODE>
<UNIT_TYPE>D</UNIT_TYPE>
<FUND_AMOUNT>125.00</FUND_AMOUNT>
</RegularInvestmentAsset>
<RegularInvestmentAsset>
<FUND_CODE>jk12</FUND_CODE>
<UNIT_TYPE>C</UNIT_TYPE>
<FUND_AMOUNT>125.00</FUND_AMOUNT>
</RegularInvestmentAsset>
</Assets>
</criteria>
</CreateClient>
I used the following xslt :
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://ufus.com/us/webservices" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<CreateClient>
<criteria>
<regioncode>524002</regioncode>
<Status>Y</Status>
<Assets>
<xsl:for-each select="descendant::*[starts-with(local-name(), 'FUND_AMOUNT')]">
<xsl:variable name="pos" select="position()"/>
<RegularInvestmentAsset>
<FUND_CODE><xsl:value-of select="../*[local-name() = concat('FUND_CODE', $pos)]"/></FUND_CODE>
<UNIT_TYPE><xsl:value-of select="../*[local-name() = concat('UNIT_TYPE', $pos)]"/></UNIT_TYPE>
<FUND_AMOUNT><xsl:value-of select="../*[local-name() = concat('FUND_AMOUNT', $pos)]"/></FUND_AMOUNT>
</RegularInvestmentAsset>
</xsl:for-each>
</Assets>
</criteria>
</CreateClient>
</xsl:template>
</xsl:stylesheet>
It worked well when i give the above input xml but when i give the input xml as below i.e starting with FUND_AMOUNT3 with out FUND_AMOUNT1 and FUND_AMOUNT2 , fund amount is not populating . i am attaching output xml also
<LMPRequests>
<LMPRequest>
<LMPMessage>Details
<Section>Criteria
<Row>
<REGION_CODE>524002</REGION_CODE>
<STATUS>Y</STATUS>
<FUND_AMOUNT3>125.00</FUND_AMOUNT3>
<FUND_CODE3>jk12</FUND_CODE3>
<UNIT_TYPE3>C</UNIT_TYPE3>
</Row>
</Section>
</LMPMessage>
</LMPRequest>
</LMPRequests>
output xml :
<?xml version="1.0" encoding="UTF-8"?>
<CreateClient xmlns="http://ufus.com/us/webservices">
<criteria>
<regioncode>524002</regioncode>
<Status>Y</Status>
<Assets>
<RegularInvestmentAsset>
<FUND_CODE></FUND_CODE>
<UNIT_TYPE></UNIT_TYPE>
<FUND_AMOUNT></FUND_AMOUNT>
</RegularInvestmentAsset>
</Assets>
</criteria>
</CreateClient>
CAn any one please help me in fixing the above problem.
|