I have attached XML file and I want to copy only the node which attribute value is something, In my case AHC_. In each node any attribute has value starting with 'AHC_' copy that node and ignore other nodes.
I am trying with following XSL and condition is working but not copying the node.Could you please take a look and suggest?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<xsl:strip-space elements="*"/>
<xsl:template match="Schedules">
<xsl:if test="Schedule[#ServiceName='MESAVisToolkit_RetentionProcessor']">
<xsl:apply-templates select="#*|node()"/>
</xsl:if>
</xsl:template>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Sample XML:
<?xml version="1.0" encoding="UTF-8"?>
<Schedules>
<Schedule OrganizationKey=" " ScheduleID="13" ServiceName="RetentionProcessor">
<TimingXML>
<days>
<day ofWeek="-1">
<times>
<time>0200</time>
</times>
</day>
</days>
<excludedDates/>
</TimingXML>
</Schedule>
<Schedule OrganizationKey=" " ScheduleID="14" ServiceName="MESAVisToolkit_RetentionProcessor">
<TimingXML>
<days>
<day ofWeek="-1">
<times>
<time>0300</time>
</times>
</day>
</days>
</TimingXML>
</Schedule>
<Schedule OrganizationKey=" " ScheduleID="15" ServiceName="MailboxEvaluateAllAutomaticRules">
<TimingXML>
<days>
<day ofWeek="-1">
<times>
<timeRange>
<range>0000-2359</range>
<interval>1</interval>
<onMinute>0</onMinute>
</timeRange>
</times>
</day>
</days>
<excludedDates/>
</TimingXML>
</Schedule>
<Schedule OrganizationKey=" " ScheduleID="16" ServiceName="MailboxEvaluateAllAutomaticRulesSubMin">
<TimingXML>
<days>
<day ofWeek="-1">
<times>
<timeRange>
<range>0000-2359</range>
<interval>1</interval>
<onMinute>0</onMinute>
</timeRange>
</times>
</day>
</days>
</TimingXML>
</Schedule>
<Schedule OrganizationKey=" " ScheduleID="51" ServiceName="AHC_001_01_0100_Get_Schedule">
<TimingXML>
<days>
<day ofWeek="-1">
<times>
<timeRange>
<range>0000-2359</range>
<interval>5</interval>
<onMinute>0</onMinute>
</timeRange>
</times>
</day>
</days>
</TimingXML>
</Schedule>
<Schedule OrganizationKey=" " ScheduleID="54" ServiceName="AHC_001_01_0200_Get_Schedule">
<TimingXML>
<days>
<day ofWeek="-1">
<times>
<timeRange>
<range>0000-2359</range>
<interval>5</interval>
<onMinute>0</onMinute>
</timeRange>
</times>
</day>
</days>
</TimingXML>
</Schedule>
</Schedules>
Expected Output:
<?xml version="1.0" encoding="UTF-8"?>
<Schedule OrganizationKey=" " ScheduleID="51" ServiceName="AHC_001_01_0100_Get_Schedule">
<TimingXML>
<days>
<day ofWeek="-1">
<times>
<timeRange>
<range>0000-2359</range>
<interval>5</interval>
<onMinute>0</onMinute>
</timeRange>
</times>
</day>
</days>
</TimingXML>
</Schedule>
<Schedule OrganizationKey=" " ScheduleID="54" ServiceName="AHC_001_01_0200_Get_Schedule">
<TimingXML>
<days>
<day ofWeek="-1">
<times>
<timeRange>
<range>0000-2359</range>
<interval>5</interval>
<onMinute>0</onMinute>
</timeRange>
</times>
</day>
</days>
</TimingXML>
</Schedule>
</Schedules>
condition is working but not copying the node.
That's not true. All Schedule nodes are copied, without condition. That's because your condition makes no sense. It makes no sense because it has nothing to do with what you said you want:
In each node any attribute has value starting with 'AHC_' copy that
node
Even more importantly, it makes no sense because it is evaluated from the context of the parent Schedules element, not the individual Schedule nodes. Thus, if any Schedule child satisfies the condition, you will be applying templates to (i.e. copying) all of them.
To selectively copy only Schedule elements that satisfy some condition, you should structure your stylesheet as:
<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="*"/>
<xsl:template match="/Schedules">
<xsl:copy>
<xsl:copy-of select="Schedule[--your condition goes here---]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Related
Below is my input XML. Here I have two different SHOWSHIPMENT files and I want to merge them to one using the data of the first occurrence of SHOWSHIPMENT for all the fields and grouping the second RL_DEATILS into the first SHOWSHIPMENT
INPUT:
<SHOW>
<SHOWSHIPMENT>
<APPLICATIONAREA>
<SENDER>
<LOGICALID>ABC</LOGICALID>
</SENDER>
<RECEIVERID>220911</RECEIVERID>
</APPLICATIONAREA>
<DATAAREA>
<SHIPMENT>
<X_DLV_TAB_ITEM>
<TYPE>A</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
</X_DLV_TAB_ITEM>
<X_DLV_TAB>
<X_DLV_TAB_ITEM>
<TYPE>A</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689764</DELIVERY_ID>
<NAME>46689764</NAME>
</X_DLV_TAB_ITEM>
<RL_DETAILS>
<ITEM>ONE</ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460996</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>11</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.2</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>5</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB>
</SHIPMENT>
</DATAAREA>
</SHOWSHIPMENT>
<SHOWSHIPMENT>
<APPLICATIONAREA>
<SENDER>
<LOGICALID>XYZ</LOGICALID>
</SENDER>
<RECEIVERID>220911</RECEIVERID>
</APPLICATIONAREA>
<DATAAREA>
<SHIPMENT>
<X_DLV_TAB_ITEM>
<TYPE>B</TYPE>
<TRANSACTION_CODE>AB</TRANSACTION_CODE>
</X_DLV_TAB_ITEM>
<X_DLV_TAB>
<X_DLV_TAB_ITEM>
<TYPE>B</TYPE>
<TRANSACTION_CODE>AB</TRANSACTION_CODE>
<DELIVERY_ID>466897665</DELIVERY_ID>
<NAME>46689765</NAME>
</X_DLV_TAB_ITEM>
<RL_DETAILS>
<ITEM>TWO</ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460997</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>5.28333</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.12</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>3</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB>
</SHIPMENT>
</DATAAREA>
</SHOWSHIPMENT>
</SHOW>
OUTPUT:
<SHOW>
<SHOWSHIPMENT>
<APPLICATIONAREA>
<SENDER>
<LOGICALID>ABC</LOGICALID>
</SENDER>
<RECEIVERID>220911</RECEIVERID>
</APPLICATIONAREA>
<DATAAREA>
<SHIPMENT>
<X_DLV_TAB_ITEM>
<TYPE>A</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
</X_DLV_TAB_ITEM>
<X_DLV_TAB>
<X_DLV_TAB_ITEM>
<TYPE>A</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689764</DELIVERY_ID>
<NAME>46689764</NAME>
</X_DLV_TAB_ITEM>
<RL_DETAILS>
<ITEM>ONE</ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460996</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>11</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.2</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>5</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
<RL_DETAILS>
<ITEM>TWO</ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460997</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>5.28333</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.12</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>3</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB>
</SHIPMENT>
</DATAAREA>
</SHOWSHIPMENT>
</SHOW>
In the SHOWSHIPMENT I have X_DLV_TAB_ITEM repeated twice at two different levels SHIPMENT/X_DLV_TAB_ITEM and SHIPMENT/X_DLV_TAB/X_DLV_TAB_ITEM.
Thanks Maryann.
Perhaps I am missing something, but this seems rather simple:
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="/SHOW">
<!-- process only 1st SHOWSHIPMENT -->
<xsl:apply-templates select="SHOWSHIPMENT[1]"/>
</xsl:template>
<xsl:template match="X_DLV_TAB">
<xsl:copy>
<xsl:apply-templates/>
<!-- add RL_DETAILS from 2nd SHOWSHIPMENT -->
<xsl:apply-templates select="/SHOW/SHOWSHIPMENT[2]/DATAAREA/SHIPMENT/X_DLV_TAB/RL_DETAILS"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I have an xslt sheet in which I have 2 response objects. $response1 contains a list of ids something like:
<response>
<idlist>
<id>1</id>
<id>2</id>
</idlist>
</response>
And $response2 contains a number of objects:
<response2>
<obj id="1" name="obj1"/>
<obj id="2" name="obj2"/>
<obj id="3" name="obj3"/>
<obj id="4" name="obj4"/>
</response2>
I want to make a copy of response2 but filtering out any objects where the id matches thos contained in response 1
<xsl:variable name="copy">
<xsl:copy-of select="$response2/*[not contains($response1, id)]"/>
</xsl:variable>
any ideas greatly appreciated
C
Given a well-formed input such as:
<root>
<response>
<idlist>
<id>1</id>
<id>2</id>
</idlist>
</response>
<response2>
<obj id="1" name="obj1"/>
<obj id="2" name="obj2"/>
<obj id="3" name="obj3"/>
<obj id="4" name="obj4"/>
</response2>
</root>
the following stylesheet:
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:template match="/root">
<xsl:variable name="ids" select="response/idlist/id" />
<output>
<xsl:copy-of select="response2/obj[not(#id=$ids)]"/>
</output>
</xsl:template>
</xsl:stylesheet>
will return:
<?xml version="1.0" encoding="UTF-8"?>
<output>
<obj id="3" name="obj3"/>
<obj id="4" name="obj4"/>
</output>
A better solution is to use a key to link the nodes by matching id:
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:key name="id" match="id" use="." />
<xsl:template match="/root">
<output>
<xsl:copy-of select="response2/obj[not(key('id', #id))]"/>
</output>
</xsl:template>
</xsl:stylesheet>
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 want to sort the dates in xml using xslt and my date element is validated in xsd with datatype as date below is my xml and xsl
XML
<Trade xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Symbol xsi:type="TradedSymbol" Type="Swap">
<Economic xsi:type="EconomicLeg">
<Leg xsi:type="IRLegGeneratedFixed">
<Schedule xsi:type="ScheduleGeneratorFixed">
<Date>2014-06-17</Date>
</Schedule>
</Leg>
</Economic>
</Symbol>
<Symbol xsi:type="TradedSymbol" Type="Swap">
<Economic xsi:type="EconomicDetailIRLeg">
<Leg xsi:type="IRLegFloat">
<Schedule xsi:type="ScheduleGeneratorFloat">
<Date>2018-06-17</Date>
</Schedule>
</Leg>
</Economic>
</Symbol>
<Symbol xsi:type="TradedSymbol" Type="Floor">
<Economic xsi:type="EconomicDetailIRLeg">
<Leg xsi:type="IRLegFloat">
<Schedule xsi:type="ScheduleGeneratorFloat">
<Date>2000-06-17</Date>
</Schedule>
</Leg>
</Economic>
</Symbol>
</Trade>
XSD
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="fiExoticStructuredDeal">
<fixedIncomeExoticDeal>
<frontOfficeDealDescription>Empty decription</frontOfficeDealDescription>
<component>
<frontOfficeComponentType>
<optionDetails>
<optionStyle>European</optionStyle>
<optionDates>
<adjustedDate>
<xsl:for-each select="/Trade/Symbol/Economic/Leg/Schedule">
<xsl:sort select="concat(substring-before(Date,'-'), substring-before(substring-after(Date,'- '),'-'),substring-after(substring-after(Date,'-'),'-'))" order="ascending"/>
<xsl:choose>
<xsl:when test="position() = last()">
<xsl:value-of select="Date"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</adjustedDate>
</optionDates>
</optionDetails>
</frontOfficeComponentType>
</component>
</fixedIncomeExoticDeal>
</xsl:template>
</xsl:stylesheet>
I am not able sort the Date using xslt.It always gives me the last date in Schedule element.
It will be great if someone let me know if i am missing something.
Use
<xsl:sort select="Date" order="ascending"/>
i am beginner in XSLT and i am using it to transform XML to XML
This is the source XML i receive
Source XML:
<Response>
<Pax>
<Id>1</Id>
</Pax>
<Pax>
<Id>2</Id>
</Pax>
<Travelers>
<Traveler>
<Name>ABC</Name>
</Traveler>
<Traveler>
<Name>XYZ</Name>
</Traveler>
</Travelers>
</Response>
I have written below XSLT
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="Response">
<xsl:element name="Root">
<xsl:apply-templates select="Travelers/Traveler"/>
</xsl:element>
</xsl:template>
<xsl:template match="Traveler">
<xsl:element name="Person">
<xsl:element name="PId">
<xsl:value-of select="//Pax/Id[position()]" />
</xsl:element>
<xsl:element name="Name">
<xsl:value-of select="Name" />
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Output:
<Root>
<Person>
<PId>1</PId>
<Name>ABC</Name>
</Person>
<Person>
<PId>1</PId>
<Name>XYZ</Name>
</Person>
</Root>
I would like to generate below XML output
Expected Output:
<Root>
<Person>
<PId>1</PId>
<Name>ABC</Name>
</Person>
<Person>
<PId>2</PId>
<Name>XYZ</Name>
</Person>
</Root>
As shown in above XML the only issue is with PId, it should have value 2.
Please help. Thanks.
Here's a relatively simple solution.
When this XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="/*">
<Root>
<xsl:apply-templates select="Pax" />
</Root>
</xsl:template>
<xsl:template match="Pax">
<xsl:variable name="vPosition" select="position()" />
<Person>
<PId>
<xsl:value-of select="Id" />
</PId>
<Name>
<xsl:value-of select="/*/Travelers/*[$vPosition]/Name" />
</Name>
</Person>
</xsl:template>
</xsl:stylesheet>
...is applied to the original XML:
<Response>
<Pax>
<Id>1</Id>
</Pax>
<Pax>
<Id>2</Id>
</Pax>
<Travelers>
<Traveler>
<Name>ABC</Name>
</Traveler>
<Traveler>
<Name>XYZ</Name>
</Traveler>
</Travelers>
</Response>
...the wanted result is produced:
<Root>
<Person>
<PId>1</PId>
<Name>ABC</Name>
</Person>
<Person>
<PId>2</PId>
<Name>XYZ</Name>
</Person>
</Root>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="Response">
<Root>
<xsl:for-each select="Travelers/Traveler">
<Person>
<xsl:variable name="index" select="position()" />
<Pid><xsl:value-of select="//Pax[$index]/Id"/></Pid>
<Name><xsl:value-of select="Name"/></Name>
</Person>
</xsl:for-each>
</Root>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>
<xsl:template match="/Response">
<Root>
<xsl:for-each select="Pax">
<xsl:variable name="pos" select="position()"/>
<Person>
<PId>
<xsl:value-of select="Id"/>
</PId>
<xsl:apply-templates select="//Travelers">
<xsl:with-param name="pos" select="$pos"/>
</xsl:apply-templates>
</Person>
</xsl:for-each>
</Root>
</xsl:template>
<xsl:template match="Travelers">
<xsl:param name="pos"/>
<xsl:for-each select="//Name">
<xsl:if test="position()=$pos">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>