I'm having a bit of trouble selecting exactly what I want in the following input XML.
I need to essentially select by keys/key , where there are multiple <key> child nodes.
For example, here's a sample input XML file :
<Outbound environment="" request="selectPortfolios">
<body matchedRecordCount="4">
<portfolioSummary portfolioId="36">
<portfolio id="36">
<currency>USD</currency>
<keys>
<key displayValue="DummyCounterpartyIRS" sequenceNumber="100" sequenceValue="DummyCounterpartyIRS" type="Counterparty" value="DummyCounterpartyIRS"/>
<key displayValue="Internal VaR IRS LCH" sequenceNumber="2000" sequenceValue="80" type="ExpType" value="InternalVaR_IRS_LCH"/>
</keys>
<status>Unapproved</status>
</portfolio>
<exposureProfile>
<node date="2014-05-06">
<tag>HSVaR 5D 100 ES</tag>
<exposure>492692</exposure>
</node>
</exposureProfile>
</portfolioSummary>
<portfolioSummary portfolioId="37">
<portfolio id="37">
<currency>USD</currency>
<keys>
<key displayValue="DummyCounterpartyIRS" sequenceNumber="100" sequenceValue="DummyCounterpartyIRS" type="Counterparty" value="DummyCounterpartyIRS"/>
<key displayValue="Internal VaR CDS LCH" sequenceNumber="2000" sequenceValue="81" type="ExpType" value="InternalVaR_CDS_LCH"/>
</keys>
<status>Unapproved</status>
</portfolio>
<exposureProfile>
<node date="2014-05-09">
<tag>Node Scenario 4</tag>
<exposure>248057</exposure>
</node>
<node date="2014-05-10">
<tag>Node Scenario 5</tag>
<exposure>373130</exposure>
</node>
<node date="2014-05-11">
<tag>EXPECTED_SHORTFALL 99.7</tag>
<exposure>373130</exposure>
</node>
</exposureProfile>
</portfolioSummary>
<portfolioSummary portfolioId="71">
<readOnly>false</readOnly>
<portfolio id="71">
<currency>USD</currency>
<keys>
<key displayValue="DummyCounterpartyCDS" sequenceNumber="100" sequenceValue="DummyCounterpartyCDS" type="Counterparty" value="DummyCounterpartyCDS"/>
<key displayValue="Internal VaR IRS LCH" sequenceNumber="2000" sequenceValue="80" type="ExpType" value="InternalVaR_IRS_LCH"/>
</keys>
<status>Unapproved</status>
</portfolio>
<exposureProfile>
<node date="2014-05-06">
<tag>HSVaR 5D 100 ES</tag>
<exposure>58</exposure>
</node>
</exposureProfile>
</portfolioSummary>
<portfolioSummary portfolioId="72">
<readOnly>false</readOnly>
<portfolio id="72">
<currency>USD</currency>
<keys>
<key displayValue="DummyCounterpartyCDS" sequenceNumber="100" sequenceValue="DummyCounterpartyCDS" type="Counterparty" value="DummyCounterpartyCDS"/>
<key displayValue="Internal VaR CDS LCH" sequenceNumber="2000" sequenceValue="81" type="ExpType" value="InternalVaR_CDS_LCH"/>
</keys>
<status>Unapproved</status>
</portfolio>
<exposureProfile>
<node date="2014-05-09">
<tag>Node Scenario 4</tag>
<exposure>9</exposure>
</node>
<node date="2014-05-10">
<tag>Node Scenario 5</tag>
<exposure>12</exposure>
</node>
<node date="2014-05-11">
<tag>EXPECTED_SHORTFALL 99.7</tag>
<exposure>12</exposure>
</node>
</exposureProfile>
</portfolioSummary>
</body>
</Outbound>
The specific <portfolioSummary> nodes I want are based on the <key> attributes:
1) First XSLT template:
1a) where attribute type="Counterparty" and value="DummyCounterpartyIRS" AND
1b) where attribute type="ExpType" AND value="InternalVaR_IRS_LCH"
2) Second XSLT template:
2a) where attribute type="Counterparty" value="DummyCounterpartyCDS" AND
2b) where attributes type="ExpType" AND value="InternalVaR_CDS_LCH"
It should end up pulling TWO <portfolioSummary> nodes for both portfolioId="36" and portfolioId="72"
Here's what I have, but it's not selecting properly:
<?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>
<!-- Pull portfolioSummary nodes for HSVaR -->
<xsl:template match="/*">
<collection>
<xsl:apply-templates select="/Outbound/body/portfolioSummary[descendant::portfolio/keys/key[#type='Counterparty' and #value='DummyCounterpartyIRS']]"/>
<xsl:apply-templates select="/Outbound/body/portfolioSummary[descendant::portfolio/keys/key[#type='Counterparty' and #value='DummyCounterpartyCDS']]"/>
</collection>
</xsl:template>
<xsl:template match="*">
<xsl:choose>
<xsl:when test="descendant::portfolio/keys/key[#type='ExpType' and #value='InternalVaR_IRS_LCH']">
<extIA>
<AGREEMENTID><xsl:value-of select="#portfolioId"></xsl:value-of></AGREEMENTID>
<legal_id><xsl:value-of select="portfolio/keys/key[#type='Counterparty']/#displayValue"/></legal_id>
<PRODUCT><xsl:value-of select="portfolio/keys/key[#type='Counterparty']/#displayValue"/></PRODUCT>
<AMOUNT><xsl:value-of select="exposureProfile/node[tag/text()[contains(.,$hsVar5D)]]/exposure"/></AMOUNT>
<CURRENCY><xsl:value-of select="bandStructure/currency"/></CURRENCY>
<ValuationDate>2012-05-15</ValuationDate>
<externalSystem>MY EXT SYSTEM</externalSystem>
</extIA>
</xsl:when>
<xsl:when test="descendant::portfolio/keys/key[#type='ExpType' and #value='InternalVaR_CDS_LCH']">
<extIA>
<AGREEMENTID><xsl:value-of select="#portfolioId"></xsl:value-of></AGREEMENTID>
<legal_id><xsl:value-of select="portfolio/keys/key[#type='Counterparty']/#displayValue"/></legal_id>
<PRODUCT><xsl:value-of select="portfolio/keys/key[#type='ExpType']/#displayValue"/></PRODUCT>
<AMOUNT><xsl:value-of select="exposureProfile/node[tag/text()[contains(.,$hsVar5D)]]/exposure"/></AMOUNT>
<CURRENCY><xsl:value-of select="bandStructure/currency"/></CURRENCY>
<ValuationDate>2012-05-15</ValuationDate>
<externalSystem>MY EXT SYSTEM</externalSystem>
</extIA>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
The <xsl:apply-templates> in your first template are not selecting anything. You are matching /* and selecting an absolute location path which starts with an element that does not exist: razorOutbound.
Change it to:
<xsl:template match="/">
<collection>
<xsl:apply-templates select="Outbound/body/portfolioSummary[descendant::portfolio/keys/key[#type='Counterparty' and #value='DummyCounterpartyIRS']]"/>
<xsl:apply-templates select="Outbound/body/portfolioSummary[descendant::portfolio/keys/key[#type='Counterparty' and #value='DummyCounterpartyCDS']]"/>
</collection>
</xsl:template>
As for the selections, four portfolios are selected, and not two. The first expression:
//body/portfolioSummary[portfolio/keys/key[#type='Counterparty' and #value='DummyCounterpartyIRS']]
will match two portfolios (36 and 37), and the other will match 71 and 72. The * template will be called twice for each pair and will always match one or the other xsl:when. If you want to select only one of each, you have to add some other restriction to it.
Related
could you please assist with solution below.
The sources files some times missing hole segment (which has child 'count' element with number 3). In this case I need to map all missing node segment and add some specific values.
Please see correct source xml file below which has all 'node' segments.
<?xml version="1.0" encoding="utf-8"?>
<root>
<group>
<node segment="1">
<count>2</count>
<value>value_2</value>
</node>
<node segment="1">
<count>3</count>
<value>value_3</value>
</node>
<node segment="1">
<count>1</count>
<value>value_1</value>
</node>
</group>
</root>
The below one doesn't have all segments in place.
<?xml version="1.0" encoding="utf-8"?>
<root>
<group>
<node segment="1">
<count>2</count>
<value>value_2</value>
</node>
<node segment="1">
<count>1</count>
<value>value_1</value>
</node>
</group>
</root>
Mising part is:
<node segment="1">
<count>3</count>
<value>value_3</value>
</node>
I have worked on xslt script below which doesn't give me the correct output results. Please assist
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="root/group[not(node/count='3')]">
<xsl:copy>
<xsl:apply-templates select="#*"/>
<node>
<count><xsl:value-of select="'some_results'"></xsl:value-of></count>
<value><xsl:value-of select="'some_results'"/></value>
</node>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node[not(count='3')]">
<xsl:copy>
<xsl:apply-templates select="#*"/>
<count><xsl:value-of select="count"></xsl:value-of></count>
<value><xsl:value-of select="value"/></value>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
If element 'node' which has child element 'count'=3 present,- map as it is.
Otherwise the output would be:
<?xml version="1.0" encoding="utf-8"?>
<root>
<group>
<node segment="1">
<count>2</count>
<value>value_2</value>
</node>
<node segment="1">
<count>some_results</count>
<value>some_results</value>
</node>
<node segment="1">
<count>1</count>
<value>value_1</value>
</node>
</group>
</root>
Thanks,
Darius
Couldn't it be simply:
XSLT 1.0
<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"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="group[not(node/count='3')]">
<xsl:copy>
<!-- add missing node-->
<node segment="1">
<count>some_results</count>
<value>some_results</value>
</node>
<!-- process existing nodes -->
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
input:
<DS>
<TL>
<msg>
<output_getquerydata>
<queries>
<query name="q1">
<parameters>
<parameter name="id">906OREA</parameter>
</parameters>
<results>
<record>
<column name="actionState">sdss</column>
</record>
</results>
</query>
<query name="q2">
<parameters>
<parameter name="resCode">CTL</parameter>
<parameter name="prodCode">89CMID</parameter>
<parameter name="pos">1,2,4,3</parameter>
</parameters>
<results>
<record id="1">
<column name="position">1</column>
<column name="ExternalProductId"/>
</record>
<record id="9">
<column name="position"/>
<column name="ExternalProductId">316442</column>
</record>
</results>
</query>
<query name="q2">
<parameters>
<parameter name="resCode">CTL</parameter>
<parameter name="prodCode">91VPRM</parameter>
<parameter name="pos">1,2,4,3</parameter>
</parameters>
<results>
<record id="1">
<column name="position"/>
<column name="ExternalProductId">316495</column>
</record>
</results>
</query>
</queries>
</output_getquerydata>
</msg>
<TL>
<ArticleNr>89CMID</ArticleNr>
</TL>
<TL>
<ArticleNr>89CMID</ArticleNr>
</TL>
<TL>
<ArticleNr>89CMID</ArticleNr>
</TL>
<TL>
<ArticleNr>91VPRM</ArticleNr>
</TL>
</TL>
</DS>
XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="Article" match="tLoading" use="./ArticleNr"/>
<xsl:key name="prod" match="query[#name='q2']/results/record" use="./column[#name='ExternalProductId'][node()]"/>
<xsl:template match="DS">
<msglist>
<xsl:for-each select="./TL[./msg/output_getquerydata/queries/query/results/record/column[#name='actionState'] !='finished'] ">
<xsl:variable name="distinctArticle" select="//TL[string(ArticleNr)][count(. | key('Article',ArticleNr)[1]) = 1]"/>
<msg>
<xsl:for-each select="$distinctArticle">
<load-part>
<!--I need here the value from column[#name='ExtPR'], that has parameter[#name='prodCode']=the current TL articleNr node.
-->
<productId>
<xsl:value-of select="key('prod',column[#name='ExternalProductId'])"/>
</productId>
<!--something-->
</load-part>
</xsl:for-each>
</msg>
</xsl:for-each>
</msglist>
</xsl:template>
</xsl:stylesheet>
Desired OUTPUT:
<msglist>
<msg>
<load-part>
<productId>316442</productId>
</load-part>
<load-part>
<productId>316442</productId>
</load-part>
<load-part>
<productId>316442</productId>
</load-part>
<load-part>
<productId>316495</productId>
</load-part>
</msg>
</msglist>
I need in the productID node, the value from column[#name='ExternalProductId'], that has parameter[#name='prodCode']=the current <TL><ArticleNr> node.
I know that this 'for each' code that I've put, returns only two values, because i'm searching for the distinct values, so I was thinking that I will try with a key, but i'm not sure what I am missing.
Thank you
edited for the correct output values
Firstly, your Article key looks wrong (in the context of your question) as there are no tLoading elements in your XML. So it should be this...
<xsl:key name="Article" match="TL" use="ArticleNr"/>
But to answer your direct question, you need to define your prod key like so
<xsl:key name="prod"
match="query[#name='q2']/results/record"
use="../../parameters/parameter[#name='prodCode']"/>
Then, to look it up, do this...
<xsl:value-of select="key('prod', ArticleNr)/column[#name='ExternalProductId']"/>
Or maybe this, as they "q2" query has two ExternalProductIds...
<xsl:value-of select="key('prod', ArticleNr)/column[#name='ExternalProductId'][. != '']"/>
Try this XSLT (which retains your distinct check, and so only outputs two rows)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:key name="Article" match="TL" use="ArticleNr"/>
<xsl:key name="prod" match="query[#name='q2']/results/record" use="../../parameters/parameter[#name='prodCode']"/>
<xsl:template match="DS">
<msglist>
<xsl:for-each select="./TL[./msg/output_getquerydata/queries/query/results/record/column[#name='actionState'] !='finished'] ">
<xsl:variable name="distinctArticle" select="//TL[string(ArticleNr)][count(. | key('Article',ArticleNr)[1]) = 1]"/>
<msg>
<xsl:for-each select="$distinctArticle">
<load-part>
<productId>
<xsl:value-of select="ArticleNr" />
<xsl:text> - </xsl:text>
<xsl:value-of select="key('prod', ArticleNr)/column[#name='ExternalProductId'][. != '']"/>
</productId>
</load-part>
</xsl:for-each>
</msg>
</xsl:for-each>
</msglist>
</xsl:template>
</xsl:stylesheet>
I have a generic template I've designed with 2 params title and category.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:param name="category" />
<xsl:param name="title" />
<xsl:template name="test-group">
<fo:block>
<xsl:value=of select="$title" />
</fo:block>
<fo:block>
<xsl:value-of select="$category" />
</fo:block>
</xsl:template>
</xsl:stylesheet>
In the parent template I have the following:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:include href="templates/generic_template.xsl" />
...
<xsl:call-template name="test-group">
<xsl:with-param name="category" select="'animals'" />
<xsl:with-param name="title" select="'DOGS'" />
</xsl:call-template>
...
</xsl:stylesheet>
However, when the transform completes title and category are blank. I'm using FOP 2.0 so I'm not sure if this is a known shortcoming.
When defining a xsl:template that takes parameters, the parameter names used within the xsl:template should be declared using xls:param elements nested within.
<xsl:template name="test-group">
<xsl:param name="category" />
<xsl:param name="title" />
...
</xsl:template>
The parameters being attached to the xsl:template and not the xsl:stylesheet.
This is similar to when calling the template with xsl:call-template, except you are specifying the values instead using xsl:with-param.
I have the following XML format below, where my main repeating node is
<portfolioSummary>...</portfolioSummary>
One of the descendent nodes is
<keys>
<key>...</key>
<key>...</key>
</keys>
and as you can see, there are multiple <key> child nodes.
I would like to set up an XSLT template whereby I'm selecting all <portfolioSummary> nodes where keys/key[displayValue='HSVaR'] .
My XML input sample set is :
<?xml version="1.0" encoding="UTF-8"?>
<outBound>
<body>
<portfolioSummary portfolioId="61">
<portfolio id="42">
<currency>USD</currency>
<keys>
<key displayValue="My Company Inc" sequenceValue="My Company Inc" sequenceNumber="30" value="My Company Inc" />
<key displayValue="COUNTERPARTY IRS" sequenceValue="COUNTERPARTY IRS" sequenceNumber="50" value="COUNTERPARTY IRS" />
<key displayValue="Historical VaR" sequenceNumber="330" value="HSVaR" />
</keys>
</portfolio>
<exposureProfile>
<node date="2008-08-08">
<tag>HSVaR 5D 99.7 ES</tag>
<exposure>16250079</exposure>
</node>
</exposureProfile>
<summary>
<util>33000000</util>
</summary>
</portfolio>
</portfolioSummary>
</body>
</outBound>
My desired OUTPUT with sample is (where <extIA>..</extIA> may be repeated many times over) :
<?xml version="1.0" encoding="UTF-8"?>
<collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<extIA>
<legal_id>My Company Inc</legal_id>
<AMOUNT>16250079</AMOUNT>
<CURRENCY>USD</CURRENCY>
<ValuationDate>2008-08-08</ValuationDate>
<externalSystem>myExternalSystem123</externalSystem>
</extIA>
<extIA>
<legal_id>My Company Inc</legal_id>
<AMOUNT>100000</AMOUNT>
<externalSystem>myExternalSystem123</externalSystem>
</extIA>
</collection>
and my XSLT starter code is the following (just some starter ideas):
<?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"
version="1.0"
indent="yes">
<xsl:template match="/*">
<collection>
<xsl:apply-templates select="/outbound/body/portfolioSummary"/>
</collection>
</xsl:template>
<!-- Pull portfolioSummary nodes -->
<xsl:template match="portfolio/keys/key[#value='HSVAR']">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*">
<extIA>
<legal_id><xsl:value-of select="#portfolioId"></xsl:value-of></legal_id>
<PRODUCT><xsl:value-of select="summary"/></PRODUCT>
<AMOUNT><xsl:value-of select="exposureProfile"></xsl:value-of></AMOUNT>
<CURRENCY>USD</CURRENCY>
<ValuationDate>2012-05-15</ValuationDate>
<externalSystem>My External System</externalSystem>
</extIA>
</xsl:template>
</xsl:stylesheet>
Again, I would be needing to pull all of those <portfolioSummary> nodes, but ONLY where portfolio/keys/key[#value='HSVAR'] .
Your advice would be greatly appreciated.
I would like to take a guess here. Given the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<outBound>
<body>
<portfolioSummary portfolioId="42">
<portfolio id="42">
<currency>USD</currency>
<keys>
<key displayValue="My Company Inc" sequenceValue="My Company Inc" sequenceNumber="30" value="My Company Inc" />
<key displayValue="COUNTERPARTY IRS" sequenceValue="COUNTERPARTY IRS" sequenceNumber="50" value="COUNTERPARTY IRS" />
<key displayValue="Historical VaR" sequenceNumber="330" value="HSVaR" />
</keys>
<exposureProfile>
<node date="2008-08-08">100000</node>
</exposureProfile>
<summary>
<util>33000000</util>
</summary>
</portfolio>
</portfolioSummary>
</body>
</outBound>
and the following stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template match="/">
<collection>
<xsl:apply-templates select="/outBound/body/portfolioSummary[descendant::key/#value[.='HSVaR']]"/>
</collection>
</xsl:template>
<xsl:template match="portfolioSummary">
<extIA>
<legal_id><xsl:value-of select="#portfolioId"/></legal_id>
<PRODUCT><xsl:value-of select="descendant::summary/util"/></PRODUCT>
<AMOUNT><xsl:value-of select="descendant::exposureProfile/node"/></AMOUNT>
<CURRENCY><xsl:value-of select="descendant::currency"/></CURRENCY>
<ValuationDate><xsl:value-of select="descendant::exposureProfile/node/#date"/></ValuationDate>
<externalSystem>RAZOR</externalSystem>
</extIA>
</xsl:template>
</xsl:stylesheet>
it outputs:
<?xml version="1.0" encoding="utf-8"?>
<collection>
<extIA>
<legal_id>42</legal_id>
<PRODUCT>33000000</PRODUCT>
<AMOUNT>100000</AMOUNT>
<CURRENCY>USD</CURRENCY>
<ValuationDate>2008-08-08</ValuationDate>
<externalSystem>RAZOR</externalSystem>
</extIA>
</collection>
I am having two xml files. I want to copy one xml file data into another file under last occurrence of element. Below are the xml I am having :
---------- xml-1---------------
<?xml version="1.0"?>
<parent>
....
<form id="1" name="world"/>
<source id="1" name="abc1"/>
<source id="2" name="abc2"/>
<source id="3" name="abc3"/>
<file id="1" name="xyz"/>
....
</parent>
----------- xml-2--------------
<?xml version="1.0"?>
<root>
<source id="4" data="anything"/>
<source id="5" data="anything"/>
<source id="6" data="anything"/>
<source id="7" data="anything"/>
</root>
------------------The desired output I want-----------------
<?xml version="1.0"?>
<parent>
....
<source id="1" name="abc1"/>
<source id="2" name="abc2"/>
<source id="3" name="abc3"/>
<source id="4" data="anything"/>
<source id="5" data="anything"/>
<source id="6" data="anything"/>
<source id="7" data="anything"/>
<file id="1" name="xyz"
....
</parent>
============== xslt I am using =============
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|#*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="source">
<xsl:choose>
<xsl:when test="'id=3'">
<xsl:call-template name="identity"/>
<xsl:copy-of select="document('file:///D:/Softwares/JEE eclipse/JEEworkspace/Migration/TestMigrationWithoutDeletingProject/xml2.xml')/*/*"/>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
I am trying to find it out on the basis of id attribute but it is copying xml-2 data after every source element of xml-1 data. Please help me on this.
I think there are two small problems in your code:
The call to <xsl:call-template name="identity"/> should be outside (or rather before) your choose section. By the way: since you not have an otherwise section it would be slightly shorter to use xsl:if here.
The test for the correct insertion point should be test="#id = 3" since the term "'id=3'" is simply a string which always yields true().