I am new to xslt and trying to create one XSLT ,
I am calling aother template with passing param value to it
But somehow blank value is coming in param variable for destination template.
Here is the simplified sample xml file :
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<TCXML xmlns="http://www.tcxml.org/Schemas/TCXMLSchema">
<BOMWindow elemId="id62" revision_rule="id60" top_line="id2">
<GSIdentity elemId="id1" label="a00pC7EtM1CZ7D"/>
</BOMWindow>
<IMAN_Drawing elemId="id78" owning_site="id4" primary_object="#id21" secondary_object="#id25" user_data="">
<GSIdentity elemId="id50" label="R8D9sTvgBT4jNA"/>
</IMAN_Drawing>
<IMAN_Drawing elemId="id79" owning_site="#id4" primary_object="#id22" secondary_object="#id26" user_data="">
<GSIdentity elemId="id56" label="R8D9sTfVBT4jNA"/>
</IMAN_Drawing>
<IMAN_Drawing elemId="id80" owning_site="#id4" primary_object="#id20" secondary_object="#id24" user_data="">
<GSIdentity elemId="id44" label="R8A9sTu6BT4jNA"/>
</IMAN_Drawing>
<UGPART creation_date="2012-06-05T09:25:30Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id117" format_used="PART" gov_classification="" object_name="Test" owning_organization="" >
<GSIdentity elemId="id21" label="RXM9sPifBT4jNA"/>
</UGPART>
<UGPART creation_date="2012-06-05T09:25:30Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id117" format_used="PART" gov_classification="" object_name="Test2" owning_organization="" >
<GSIdentity elemId="id20" label="R3K9sPifBT4jNA"/>
</UGPART>
<UGPART creation_date="2012-06-05T09:25:30Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id117" format_used="PART" gov_classification="" object_name="Test3" owning_organization="" >
<GSIdentity elemId="id22" label="xuO9sPifBT4jNA"/>
</UGPART>
In XML there are 3 IMAN_Drawing tags, and 3 UGPART tags
Here is my xslt for this
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:plm="http://www.tcxml.org/Schemas/TCXMLSchema" version="1.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/plm:TCXML/plm:IMAN_Drawing">
<xsl:copy>
<xsl:copy-of select="#*" />
<xsl:for-each select="/plm:TCXML/plm:IMAN_Drawing">
<xsl:variable name="currentSecObjectId" select="#secondary_object"/>
<xsl:variable name="RefSecObjectId" select="substring($currentSecObjectId,2)"/>
<xsl:variable name="currentPrimaryObjectId" select="/plm:TCXML/plm:IMAN_Drawing/#primary_object"/>
<xsl:variable name="RefPrimaryObjectId" select="substring($currentPrimaryObjectId,2)"/>
<xsl:call-template name="UGPart">
<xsl:with-param name="PriId" select="$RefPrimaryObjectId"/>
</xsl:call-template>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="/plm:TCXML/plm:UGPART" name="UGPart">
<xsl:param name="PriId"/>
<xsl:copy>
<xsl:if test="#object_name="'Test'">
<xsl:attribute name="owning_organization">
<xsl:value-of select="$PriId"/>
</xsl:attribute>
</xsl:if>
<xsl:copy-of select="#*[not(name()='owning_organization')]" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
But the output is :
owning_organization=""
Expected Result is :
It should update owning_organization attribute which i am passing from template 1 with value = $RefPrimaryObjectId for UGPART when its #object_name="'Test'"
what is going wrong here ? why $RefPrimaryObjectId" value is not coming to second template.
You should really supply your expected output, otherwise it is really hard to understand what you want. I am making some-what of a guess as to your expected output based on your provided style-sheet.
I mean no disrespect and I am only trying to be helpful, but your style-sheet points to so many misconceptions, that rather than just picking my solution (provided below), you might be better off in the long term, by putting pens down and working through some published tutorials, or reading a book.
Any way ...
This style-sheet ...
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:plm="http://www.tcxml.org/Schemas/TCXMLSchema" >
<xsl:output method="xml" indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="plm:IMAN_Drawing">
<xsl:variable name="id" select="substring(#primary_object,2)" />
<xsl:copy>
<xsl:apply-templates select="#*"/>
</xsl:copy>
<xsl:for-each select="../plm:UGPART[plm:GSIdentity/#elemId=$id]" >
<xsl:copy>
<xsl:apply-templates select="#*[name()!='owning_organization' or ../#object_name!='Test']"/>
<xsl:if test="#object_name='Test'">
<xsl:attribute name="owning_organization"><xsl:value-of select="$id" /></xsl:attribute>
</xsl:if>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:for-each>
</xsl:template >
<xsl:template match="plm:UGPART" />
</xsl:stylesheet>
... when applied to your sample input, will produce output ...
<?xml version="1.0" encoding="utf-8"?>
<TCXML xmlns="http://www.tcxml.org/Schemas/TCXMLSchema">
<BOMWindow elemId="id62" revision_rule="#id60" top_line="#id2">
<GSIdentity elemId="id1" label="a00pC7EtM1CZ7D" />
</BOMWindow>
<IMAN_Drawing elemId="id78" owning_site="#id4" primary_object="#id21" secondary_object="#id25" user_data="" /><UGPART creation_date="2012-06-05T09:25:30Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id117" format_used="PART" gov_classification="" object_name="Test" owning_organization="id21">
<GSIdentity elemId="id21" label="RXM9sPifBT4jNA" />
</UGPART>
<IMAN_Drawing elemId="id79" owning_site="#id4" primary_object="#id22" secondary_object="#id26" user_data="" /><UGPART creation_date="2012-06-05T09:25:30Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id117" format_used="PART" gov_classification="" object_name="Test3" owning_organization="">
<GSIdentity elemId="id22" label="xuO9sPifBT4jNA" />
</UGPART>
<IMAN_Drawing elemId="id80" owning_site="#id4" primary_object="#id20" secondary_object="#id24" user_data="" /><UGPART creation_date="2012-06-05T09:25:30Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id117" format_used="PART" gov_classification="" object_name="Test2" owning_organization="">
<GSIdentity elemId="id20" label="R3K9sPifBT4jNA" />
</UGPART>
</TCXML>
Let us know if I have misunderstood your expected output.
Related
I want to copy the value of parentnode element into child node, as shown below. Can someone point me in the right direction on how to achieve this?
Thank you!
Here is the xml file.
<mainpart id="295928" num="1-MS15" quantity="1">
<explicitQuantity>1</explicitQuantity>
<proxy id="1E2B4D" ACADID="1E2B4E" basepart="58A67">
<singlepart id="24558D" num="1-m81" ncFile="1-m81.nc1" quantity="1">
<explicitQuantity>1</explicitQuantity>
<part id="58A67" name="C4X6.25" class="Beam" ACADID="59582" dstvName="C4X6.25">
<explicitQuantity>1</explicitQuantity>
<role key="Frame" name="FRAME"/>
<length>1727.194</length>
<paintArea>618840.532</paintArea>
<numHoles>8</numHoles>
<ObjectTopLevel>0.739</ObjectTopLevel>
<ObjectBottomLevel>-101.741</ObjectBottomLevel>
<material key="ASTM-A36" name="A36"/>
<coating key="G" name="G"/>
<commodity>FRAME</commodity>
<weight>16064.68</weight>
<exactWeight>15945.55</exactWeight>
<weightPerMeter>9301.02</weightPerMeter>
<density>7850.00</density>
<section key="AISC 14.1 C Channel##§##ChannelsC4X6.25" name="C4X6.25"/>
<sysLength>1727.194</sysLength>
<sawLength>1727.194</sawLength>
<angleX1>0.0000</angleX1>
<angleY1>0.0000</angleY1>
<angleX2>0.0000</angleX2>
<angleY2>0.0000</angleY2>
<SawCutInfo>0</SawCutInfo>
<ElementID>7400</ElementID>
</part>
</singlepart>
<singlepart id="295ADA" num="1-p3" quantity="4">
<explicitQuantity>4</explicitQuantity>
<part id="295C18" name="PL 1/4"x1 3/8"" class="Plate" ACADID="295C14" dstvName="PL 1/4"">
<explicitQuantity>1</explicitQuantity>
<role key="Plate" name="PLATE"/>
<length>85.725</length>
<paintArea>7215.343</paintArea>
<ObjectTopLevel>-7.199</ObjectTopLevel>
<ObjectBottomLevel>-93.396</ObjectBottomLevel>
<material key="ASTM-A36" name="A36"/>
<coating key="G" name="G"/>
<weight>143.81</weight>
<exactWeight>143.81</exactWeight>
<density>7850.00</density>
<thickness>6.350</thickness>
<width>35.535</width>
<area1>2884.914</area1>
<area2>2884.914</area2>
<contourLength>227.640</contourLength>
<ElementID>52306</ElementID>
<ElementID>52304</ElementID>
<ElementID>52303</ElementID>
<ElementID>52305</ElementID>
</part>
</singlepart>
</proxy>
</mainpart>
Here is my xsl, I know it is wrong, but I can't figure out how to fix it.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="mainpart" >
<xsl:variable name="mainpartmark" select="#name" />
<xsl:copy>
<xsl:apply-templates select="#*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="part">
<xsl:copy>
<xsl:apply-templates select="#*|node()" />
<UserAttribute10>"$mainpartmark"</UserAttribute10>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Here is the result I wanted, I want to add the node UserAttr10 on each end of Part node with value of num from mainpart node.
<mainpart id="295928" num="1-MS15" quantity="1">
<explicitQuantity>1</explicitQuantity>
<proxy id="1E2B4D" ACADID="1E2B4E" basepart="58A67">
<singlepart id="24558D" num="1-m81" ncFile="1-m81.nc1" quantity="1">
<explicitQuantity>1</explicitQuantity>
<part id="58A67" name="C4X6.25" class="Beam" ACADID="59582" dstvName="C4X6.25">
<explicitQuantity>1</explicitQuantity>
<role key="Frame" name="FRAME"/>
<length>1727.194</length>
<paintArea>618840.532</paintArea>
<numHoles>8</numHoles>
<ObjectTopLevel>0.739</ObjectTopLevel>
<ObjectBottomLevel>-101.741</ObjectBottomLevel>
<material key="ASTM-A36" name="A36"/>
<coating key="G" name="G"/>
<commodity>FRAME</commodity>
<weight>16064.68</weight>
<exactWeight>15945.55</exactWeight>
<weightPerMeter>9301.02</weightPerMeter>
<density>7850.00</density>
<section key="AISC 14.1 C Channel##§##ChannelsC4X6.25" name="C4X6.25"/>
<sysLength>1727.194</sysLength>
<sawLength>1727.194</sawLength>
<angleX1>0.0000</angleX1>
<angleY1>0.0000</angleY1>
<angleX2>0.0000</angleX2>
<angleY2>0.0000</angleY2>
<SawCutInfo>0</SawCutInfo>
<ElementID>7400</ElementID>
<UserAttr10>1-MS15</UserAttr10> <!--Add this line-->
</part>
</singlepart>
<singlepart id="295ADA" num="1-p3" quantity="4">
<explicitQuantity>4</explicitQuantity>
<part id="295C18" name="PL 1/4"x1 3/8"" class="Plate" ACADID="295C14" dstvName="PL 1/4"">
<explicitQuantity>1</explicitQuantity>
<role key="Plate" name="PLATE"/>
<length>85.725</length>
<paintArea>7215.343</paintArea>
<ObjectTopLevel>-7.199</ObjectTopLevel>
<ObjectBottomLevel>-93.396</ObjectBottomLevel>
<material key="ASTM-A36" name="A36"/>
<coating key="G" name="G"/>
<weight>143.81</weight>
<exactWeight>143.81</exactWeight>
<density>7850.00</density>
<thickness>6.350</thickness>
<width>35.535</width>
<area1>2884.914</area1>
<area2>2884.914</area2>
<contourLength>227.640</contourLength>
<ElementID>52306</ElementID>
<ElementID>52304</ElementID>
<ElementID>52303</ElementID>
<ElementID>52305</ElementID>
<UserAttr10>1-MS15</UserAttr10> <!--Add this line-->
</part>
</singlepart>
</proxy>
</mainpart>
As there is only one mainpart node (the root element), simply declare your variable as a global variable (a child of xsl:stylesheet)
<xsl:variable name="mainpartmark" select="/mainpart/#num" />
(You wouldn't need the template matching mainpart in this case).
Then, to use it, just do this...
<UserAttribute10>
<xsl:value-of select="/mainpart/#num" />
</UserAttribute10>
Try this XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exclude-result-prefixes="xsi">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()" />
</xsl:copy>
</xsl:template>
<xsl:variable name="mainpartmark" select="/mainpart/#num" />
<xsl:template match="part">
<xsl:copy>
<xsl:apply-templates select="#*|node()" />
<UserAttribute10>
<xsl:value-of select="$mainpartmark" />
</UserAttribute10>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Of course, you could also do it without the variable at all, and just do <xsl:value-of select="/mainpart/#num" /> instead.
And, if there were multiple mainpart nodes (under a single root element), you could also do <xsl:value-of select="ancestor::mainpart/#num" />
I need your assistance with the logic to add the end tags. The structure i am looking at is . I tried with for-each or xsl:if or xsl:choose. The input XML is as below
<SuperShipNotice>
<Package packageType="P" packageLevel="1">
<PackageNumber>PWN34332</PackageNumber>
<ShipmentNumber>105909390</ShipmentNumber>
<ShipmentLineNumber>1</ShipmentLineNumber>
<PartNumber>1CH162-510</PartNumber>
<Quantity>1000</Quantity>
<SSCCNumber>00176364909402100165</SSCCNumber>
</Package>
<Package packageType="C" packageLevel="2">
<PackageNumber>CWX612432660</PackageNumber>
<ParentPackageNumber>PWN34332</ParentPackageNumber>
<ShipmentNumber>105909390</ShipmentNumber>
<ShipmentLineNumber>1</ShipmentLineNumber>
<PartNumber>1CH162-510</PartNumber>
<Quantity>25</Quantity>
<SSCCNumber>00176364909402100165</SSCCNumber>
</Package>
<Package packageType="S" packageLevel="3">
<PackageNumber>W1D2WNGL</PackageNumber>
<ParentPackageNumber>CWX612432660</ParentPackageNumber>
<ShipmentNumber>105909390</ShipmentNumber>
<ShipmentLineNumber>1</ShipmentLineNumber>
<PartNumber>1CH162-510</PartNumber>
<Quantity>1</Quantity>
<DateOfMfg>20131209</DateOfMfg>
<COO>CN</COO>
<SSCCNumber>00176364909402100165</SSCCNumber>
</Package>
<Package packageType="S" packageLevel="3">
<PackageNumber>W1D2WNGL</PackageNumber>
<ParentPackageNumber>CWX612432660</ParentPackageNumber>
<ShipmentNumber>105909390</ShipmentNumber>
<ShipmentLineNumber>1</ShipmentLineNumber>
<PartNumber>1CH162-510</PartNumber>
<Quantity>1</Quantity>
<DateOfMfg>20131209</DateOfMfg>
<COO>CN</COO>
<SSCCNumber>00176364909402100165</SSCCNumber>
</Package>
</SuperShipNotice>
Not sure if this can be of any use for you - following XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="SuperShipNotice">
<xsl:apply-templates select="//PackageNumber[parent::Package[#packageLevel='1']]" />
</xsl:template>
<xsl:template match="PackageNumber[parent::Package[#packageLevel='1']]">
<xsl:variable name="packageNumber" select="." />
<PkgLevel1>
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
<xsl:apply-templates select="//PackageNumber[parent::Package[#packageLevel='2'] and parent::Package/ParentPackageNumber = $packageNumber]" />
</PkgLevel1>
</xsl:template>
<xsl:template match="PackageNumber[parent::Package[#packageLevel='2']]">
<xsl:variable name="packageNumber" select="." />
<PkgLevel2>
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
<xsl:apply-templates select="//PackageNumber[parent::Package[#packageLevel='3'] and parent::Package/ParentPackageNumber = $packageNumber
and not(parent::Package/ParentPackageNumber = preceding::Package[#packageLevel='3']/ParentPackageNumber)]" />
</PkgLevel2>
</xsl:template>
<xsl:template match="PackageNumber[parent::Package[#packageLevel='3']]">
<PkgLevel3>
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</PkgLevel3>
</xsl:template>
</xsl:transform>
when applied to your input XML produces the output
<PkgLevel1>
<PackageNumber>PWN34332</PackageNumber>
<PkgLevel2>
<PackageNumber>CWX612432660</PackageNumber>
<PkgLevel3>
<PackageNumber>W1D2WNGL</PackageNumber>
</PkgLevel3>
</PkgLevel2>
</PkgLevel1>
The first template matching SuperShipNotice applies templates to PackageNumbers of Packages with the packageLevel value 1.
In the template matching those Packagenumbers templates are applied to all PackageNumbers with the packageLevel value 2 and the ParentPackageNumber of the current PackageNumber.
As there is a double entry for Packages with the packageLevel value 3, the second Package with the same ParentPackageNumber is omitted:
select="//PackageNumber[parent::Package[#packageLevel='3']
and parent::Package/ParentPackageNumber = $packageNumber
and not(parent::Package/ParentPackageNumber = preceding::Package[#packageLevel='3']/ParentPackageNumber)]"
In case you can adjust this to fit further requirements, you can use the saved Demo
I want to display only those orders which dont have OrderLineSource = YTR. All other should be displayed....
My Sample XML :
<Orders>
<Order>
<OrderID>34209649</OrderID>
<OrderStatus>checkout_complete</OrderStatus>
<Amount>32.93</Amount>
<OrderCreation>2014-02-08T00:00:03.00</OrderCreation>
<OrderCompletion>2014-02-08T00:00:03.00</OrderCompletion>
<CustomerGUID>303965683</CustomerGUID>
<CSMPurchaserGUID>0</CSMPurchaserGUID>
<Brand>TRFE</Brand>
<SourceECommerceSystem>Framework</SourceECommerceSystem>
<Currency>GBP</Currency>
<OrderChannel>Online</OrderChannel>
<TransactionSummary>
<TransactionID>2407065</TransactionID>
<MerchantReference>TEdV-5648-34209649</MerchantReference>
<CardCategory>Personal</CardCategory>
<CardScheme>VISA Debit</CardScheme>
<CardCountry>gbr</CardCountry>
<CardIssuer>sdfsdf sdf Bank asdf</CardIssuer>
<CardStartDate>0/0</CardStartDate>
<CardExpiryDate>2016/08</CardExpiryDate>
<Amount>32.93</Amount>
<Currency>GBP</Currency>
<CardPAN>************4585</CardPAN>
<Created>2014-02-07T23:56:48</Created>
<Updated>2014-02-08T00:00:03</Updated>
<ResponseStatusCode>1</ResponseStatusCode>
<ResponseStatusReason>FULFILLED OK</ResponseStatusReason>
<HostedPageIdentifier>dsfasdf-ee85-4afa-bb6a-0afc6dc99896</HostedPageIdentifier>
<HostedPageURL>https://hps.datacash.com/hps/</HostedPageURL>
<PaymentStatus>Paid</PaymentStatus>
<PaymentType>Debit Card</PaymentType>
<NameOnCard>Miss L J adsf</NameOnCard>
<DataCashRef>56456456454</DataCashRef>
<MerchantID>545646</MerchantID>
<ThreeDCard>1</ThreeDCard>
<ThreeDRequested>1</ThreeDRequested>
<IPAddress>127.89.560.1</IPAddress>
</TransactionSummary>
<OrderLine>
<OrderLineID>84598837</OrderLineID>
<OrderID>34209649</OrderID>
<OrderLineLabel>GAREGSBV</OrderLineLabel>
<OrderLineSource>GHR</OrderLineSource>
<Quantity>1</Quantity>
<UnitPrice>32.93</UnitPrice>
<Total>32.93</Total>
<SKUCode>P0032</SKUCode>
<Title>Miss.</Title>
<FirstName>ertwer</FirstName>
<FamilyName>sdaf</FamilyName>
<DateOfBirth>1984-05-30</DateOfBirth>
<Email>sdfasdfa#hotmail.com</Email>
<Mobile>645646454</Mobile>
<PostChannel>0</PostChannel>
<TelephoneChannel>0</TelephoneChannel>
<EmailChannel>0</EmailChannel>
<TextAndOtherChannel>0</TextAndOtherChannel>
<BuildingNumber>27</BuildingNumber>
<AddressLine1>27</AddressLine1>
<AddressLine2>dsfasdf Road</AddressLine2>
<Town>London</Town>
<Country>sdfasdf er</Country>
<Postcode>KL7 2NS</Postcode>
<AddressValidated>1</AddressValidated>
<HKPolicy>
<PolicyNum>PP01754397</PolicyNum>
<ProductDescription>sadfsadfasdfgasdg</ProductDescription>
<CoverTypeDesc>Individual</CoverTypeDesc>
<SingleParentFamilyFlag>0</SingleParentFamilyFlag>
<PolicyTypeRefID>S</PolicyTypeRefID>
<PolicyTypeDesc>Sinasdfnce</PolicyTypeDesc>
<TierDesc>Classic</TierDesc>
<DestinationDesc>Worldwide including USA, Canada, Caribbean</DestinationDesc>
<TotalTravellers>1</TotalTravellers>
<NumOfAdults>1</NumOfAdults>
<NumOfUnder18>0</NumOfUnder18>
<PolicyStartDate>2014-02-08</PolicyStartDate>
<PolicyEndDate>2014-02-12</PolicyEndDate>
<BaseCost>32.93</BaseCost>
<Commission>11.18</Commission>
<UpsoldInd>0</UpsoldInd>
<TierRefID>C</TierRefID>
<DestinationRefID>W2</DestinationRefID>
<CoverTypeRefID>I</CoverTypeRefID>
<AONToPostPolicy>yes</AONToPostPolicy>
<SalesChannel>0011002</SalesChannel>
<WhereYouHeardOfUs>Press advertising</WhereYouHeardOfUs>
<TIPOLTraveller>
<TravellerUUID>1864-1</TravellerUUID>
<PolicyNum>PI0e31754397</PolicyNum>
<Title>Miss</Title>
<FirstName>sdfsf</FirstName>
<FamilyName>sdfsdf</FamilyName>
<DateOfBirth>1984-05-30</DateOfBirth>
<AgeBand>1864</AgeBand>
<DependentFlag>0</DependentFlag>
</TIPOLTraveller>
</TIPOLPolicy>
</OrderLine>
<OrderCustomerDetails>
<Title nil="true" />
<FirstName nil="true" />
<SecondName nil="true" />
<FamilyName nil="true" />
<DateOfBirth nil="true" />
<Email nil="true" />
<Telephone nil="true" />
<Mobile nil="true" />
<Gender nil="true" />
<PostChannel nil="true" />
<TelephoneChannel nil="true" />
<EmailChannel nil="true" />
<TextAndOtherChannel nil="true" />
<BuildingNumber>27</BuildingNumber>
<AddressLine1>27</AddressLine1>
<AddressLine2>asdfa Road</AddressLine2>
<Town>asdfasdf</Town>
<Country>United dsf</Country>
<Postcode>KH9 2NS</Postcode>
<AddressValidated>1</AddressValidated>
</OrderCustomerDetails>
</Order>
<Order>
<OrderID>34209674</OrderID>
<OrderStatus>checkout_complete</OrderStatus>
<Amount>11.13</Amount>
<OrderCreation>2014-02-08T00:08:40.00</OrderCreation>
<OrderCompletion>2014-02-08T00:08:40.00</OrderCompletion>
<CustomerGUID>303965688</CustomerGUID>
<CSMPurchaserGUID>0</CSMPurchaserGUID>
<Brand>TRFDS</Brand>
<SourceECommerceSystem>Framework</SourceECommerceSystem>
<Currency>GBP</Currency>
<OrderChannel>Online</OrderChannel>
<TransactionSummary>
<TransactionID>8115032</TransactionID>
<MerchantReference>JHF-0800-34209674</MerchantReference>
<CardCategory>Personal</CardCategory>
<CardScheme>VISA Debit</CardScheme>
<CardCountry>gbr</CardCountry>
<CardIssuer>Unknown</CardIssuer>
<CardStartDate>0/0</CardStartDate>
<CardExpiryDate>2016/09</CardExpiryDate>
<Amount>11.13</Amount>
<Currency>GBP</Currency>
<CardPAN>************4849</CardPAN>
<Created>2014-02-08T00:08:00</Created>
<Updated>2014-02-08T00:08:40</Updated>
<ResponseStatusCode>1</ResponseStatusCode>
<ResponseStatusReason>FULFILLED OK</ResponseStatusReason>
<HostedPageIdentifier>f3306487-d6ea-4200-9eea-99b1d6832a2e</HostedPageIdentifier>
<HostedPageURL>https://hps.dat.com/hps/</HostedPageURL>
<PaymentStatus>Paid</PaymentStatus>
<PaymentType>Debit Card</PaymentType>
<NameOnCard>Miss Jor </NameOnCard>
<DataCashRef>380010093738013</DataCashRef>
<MerchantID>21877049</MerchantID>
<ThreeDCard>1</ThreeDCard>
<ThreeDRequested>1</ThreeDRequested>
<IPAddress>86..25640.99</IPAddress>
</TransactionSummary>
<OrderLine>
<OrderLineID>84598874</OrderLineID>
<OrderID>34209674</OrderID>
<OrderLineLabel>3-1008617753325</OrderLineLabel>
<OrderLineSource>YTR</OrderLineSource>
<Quantity>1</Quantity>
<UnitPrice>11.13</UnitPrice>
<Total>11.13</Total>
<Title>Miss.</Title>
<FirstName>Jordan</FirstName>
<SecondName>oirut</SecondName>
<FamilyName>dfgsdfgs</FamilyName>
<Email>dfgsdfg#hotmail.com</Email>
<Mobile>654756464</Mobile>
<PostChannel>0</PostChannel>
<TelephoneChannel>0</TelephoneChannel>
<EmailChannel>0</EmailChannel>
<TextAndOtherChannel>0</TextAndOtherChannel>
<BuildingNumber>12</BuildingNumber>
<AddressLine1>12</AddressLine1>
<AddressLine2>sfgsdfg End Gardens</AddressLine2>
<Town>HEMEL sfgaefa</Town>
<Country>adf dgfsdfg</Country>
<Postcode>HP1 1SN</Postcode>
<OrderLineDetail>
<NameValuePair>
<Name>dfgsdfg</Name>
<Value>628</Value>
</NameValuePair>
<NameValuePair>
<Name>NameOnCard</Name>
<Value>adsfgasdgf Piper</Value>
</NameValuePair>
<NameValuePair>
<Name>DateOnCard</Name>
<Value>2014-02-05</Value>
</NameValuePair>
<NameValuePair>
<Name>CustomsOrSurcharge</Name>
<Value>CUSTOMS CHARGE TO PAY</Value>
</NameValuePair>
</OrderLineDetail>
</OrderLine>
<OrderCustomerDetails>
<Title>Miss.</Title>
<FirstName>Jordan</FirstName>
<SecondName>asdgfasdgf</SecondName>
<FamilyName nil="true" />
<DateOfBirth />
<Email>adfadf#hotmail.com</Email>
<Telephone />
<Mobile>adfasdf</Mobile>
<Gender nil="true" />
<PostChannel nil="true" />
<TelephoneChannel nil="true" />
<EmailChannel nil="true" />
<TextAndOtherChannel nil="true" />
<BuildingNumber>12</BuildingNumber>
<AddressLine1>12</AddressLine1>
<AddressLine2>adfasdf End Gardens</AddressLine2>
<Town>adsfasdf HEMPSTEAD</Town>
<Country>United asdfasdf</Country>
<Postcode>asd 1SN</Postcode>
</OrderCustomerDetails>
</Order>
</Orders>
I tried using XSLT :
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<!-- Orders -->
<xsl:template match="/*">
<xsl:element name="Orders">
<xsl:apply-templates select="./Order" />
</xsl:element>
</xsl:template>
<!-- Orders > Order -->
<xsl:template match="/Order">
<xsl:variable name="IsValid">
<xsl:call-template name="HasOrIsValidPOLine" />
</xsl:variable>
<xsl:if test="$IsValid='VALID'"> <!-- only display the order if there's a valid line under it-->
<xsl:element name="Order">
<xsl:apply-templates select=".//VORNR" />
</xsl:element>
</xsl:if>
</xsl:template>
<!-- Part Order List > Part Order > Operational BO Number -->
<xsl:template match="//VORNR">
<xsl:element name="./Order">
<xsl:apply-templates select="node()|#*"/>
<xsl:value-of select="text()"/>
</xsl:element>
</xsl:template>
<xsl:template name="HasOrIsValidPOLine">
<xsl:choose>
<xsl:when test="./OrderLineSource/text() != 'YTR'">VALID</xsl:when>
<xsl:otherwise>INVALID</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Can you provide me the solution or let me know where I am going wrong
First, your sample XML is not well-formed: It contains a closing </TIPOLPolicy> tag that doesn't match the starting <HKPolicy> tag. Change that to </HKPolicy> first.
After that, the following XSLT 1.0 does what you want:
<?xml version="1.0" encoding="UTF-8"?>
<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"/>
<!-- Identity transform -->
<!-- Default priority 0 for root node and -0.5 for the rest -->
<xsl:template match="/ | node() | #*">
<xsl:copy>
<xsl:apply-templates select="node() | #*"/>
</xsl:copy>
</xsl:template>
<!-- Do nothing for Order elements whose OrderLine/OrderLineSource equals 'YTR' -->
<!-- Default priority 0.5 -->
<xsl:template match="Order[OrderLine/OrderLineSource = 'YTR']"/>
</xsl:stylesheet>
It makes use of the identity transform and different default priorities: The identity transform with a lower default priority copies the input to the output unless another template with a higher priority exists for a given input match. This is the case for Order elements whose OrderLine/OrderLineSource descendant contains the text value 'YTR'. Due to its higher default priority, the more specific template takes precedence over the identity transform. Since the template doesn't produce any output, any matching Order elements are removed from the output.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Order[OrderLine/OrderLineSource[string() = 'YTR']]"/>
</xsl:stylesheet>
I have to achieve below.
if <m_control>/<initiator_id> is Dummy then the xml element, <note>/<reason> should be removed.Below is the hirarchy of the note element.
<o:m_content/o:application/o:product/o:client_specific_illustration/o:note>
Below is the sample xml:
<?xml version="1.0"?>
<message xmlns="http://www.origoservices.com" xmlns:ns2="http://www.w3.org/2000/09/xmldsig#">
<m_control>
<expected_response_type>synchronous</expected_response_type>
<initiator_id>Dummy</initiator_id>
<user_id>Dummy</user_id>
<responder_id>Responder</responder_id>
</m_control>
<m_content>
<b_control>
<message_version_number>3.7</message_version_number>
<submission_date>2014-04-14</submission_date>
</b_control>
<intermediary type="Test">
<rdr_basis_of_sale>
<advised_category>Independent</advised_category>
</rdr_basis_of_sale>
</intermediary>
<application>
<address id="ADPC2">
<postcode>AB24 3DB</postcode>
</address>
<address id="ADPC1">
<postcode>B14 7JG</postcode>
</address>
<personal_client id="PC1">
<title>Mr</title>
<forenames>Test</forenames>
<surname>FLtwelve</surname>
<sex>Male</sex>
<marital_status>Married</marital_status>
<date_of_birth>1950-10-16</date_of_birth>
<employment_contract>
<occupation code="AAB00021">Actuary</occupation>
<full_time_ind>No</full_time_ind>
</employment_contract>
<smoker_ind>No</smoker_ind>
<residential_status>In Own Home - With Someone Else</residential_status>
<home_address address_id="ADPC1"/>
<enhanced_underwriting>
<medical_conditions/>
</enhanced_underwriting>
<tpsdata>
<postcode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">test</postcode>
</tpsdata>
</personal_client>
<personal_client id="PC2">
<employment_contract>
<occupation code="WAB02558">Wig Maker</occupation>
<full_time_ind>Yes</full_time_ind>
</employment_contract>
<smoker_ind>Yes</smoker_ind>
<residential_status>In Own Home - Alone</residential_status>
<home_address address_id="ADPC2"/>
<enhanced_underwriting>
<medical_conditions/>
<lifestyle>
<height units="Centimetre">180</height>
<weight units="Kilogram">70</weight>
<waist units="Centimetre">81</waist>
<units_of_alcohol_per_week>1</units_of_alcohol_per_week>
<smoking_details>
<regular_smoker_ind>Yes</regular_smoker_ind>
<current_smoking>
<number_of_cigarettes_per_day>4</number_of_cigarettes_per_day>
<number_of_cigars_per_day>0</number_of_cigars_per_day>
<rolling_tobacco_per_week units="Gram">0</rolling_tobacco_per_week>
<pipe_tobacco_per_week units="Gram">0</pipe_tobacco_per_week>
<start_date>1985-09</start_date>
</current_smoking>
</smoking_details>
</lifestyle>
</enhanced_underwriting>
<tpsdata>
<postcode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">AB24 3DB</postcode>
</tpsdata>
</personal_client>
<product type="Compulsory Purchase Annuity" product_code="CPA">
<open_market_option_ind>Yes</open_market_option_ind>
<annuity type="Non Protected Rights">
<annuitant sequence_number="1" personal_client_id="PC1"/>
<with_profit_ind>No</with_profit_ind>
<contribution legislation_applicable="Post 1997">
<amount currency="GBP">391586</amount>
<source_details>
<product_type>Occupational Scheme - Defined Contribution</product_type>
<product_provider_name>Other</product_provider_name>
<transfer_ind>No</transfer_ind>
</source_details>
<adviser_charges_applicable>
<adviser_charge_applicable adviser_charge_id="ac1"/>
</adviser_charges_applicable>
</contribution>
<payment_frequency>Annually</payment_frequency>
<payment_timing_code>In Advance</payment_timing_code>
<escalation>
<change_index>Level</change_index>
<lpi_lag_basis>Statutory</lpi_lag_basis>
<proportionate_escalation_ind>No</proportionate_escalation_ind>
</escalation>
<payment_period>
<start_basis>Specified Date</start_basis>
<start_date>2014-04-14</start_date>
</payment_period>
<guaranteed_period>
<years>5</years>
</guaranteed_period>
<commuted_ind>No</commuted_ind>
<with_proportion_ind>No</with_proportion_ind>
<reversionary_annuity type="Spouse" legislation_applicable="Post 1997">
<annuitant personal_client_id="PC2"/>
<number_of_dependants>1</number_of_dependants>
<fraction_of_original_payment>
<numerator>10</numerator>
<denominator>10</denominator>
</fraction_of_original_payment>
<payment_period>
<start_basis>Next Due Date</start_basis>
</payment_period>
<overlap_ind>No</overlap_ind>
<spouse_remarriage_cease_ind>Yes</spouse_remarriage_cease_ind>
</reversionary_annuity>
</annuity>
<adviser_charges>
<adviser_charge id="ac1">
<type>Adviser</type>
<amount currency="GBP">7831.72</amount>
<facilitated_from>Annuity In Payment</facilitated_from>
<facilitated_before_product_investment_ind>Yes</facilitated_before_product_investment_ind>
<payment_frequency>Single</payment_frequency>
<reason>Initial</reason>
</adviser_charge>
</adviser_charges>
<illustration_basis>
<annuity_calculation_required>Payment</annuity_calculation_required>
</illustration_basis>
<client_specific_illustration>
<expiry_date>2014-04-28</expiry_date>
<note>
<reason>reason for failure is specified over here</reason>
</note>
<pension_annuity type="Non Protected Rights">
<total_amount currency="GBP">18539.33</total_amount>
<reversionary_annuity>
<total_amount currency="GBP">18539.33</total_amount>
</reversionary_annuity>
</pension_annuity>
<adviser_charges>
<adviser_charge>
<adviser_charge_requested adviser_charge_id="ac1"/>
<type>Adviser</type>
<amount currency="GBP">7831.72</amount>
<facilitated_from>Annuity In Payment</facilitated_from>
<facilitated_before_product_investment_ind>Yes</facilitated_before_product_investment_ind>
<payment_frequency>Single</payment_frequency>
<reason>Initial</reason>
</adviser_charge>
</adviser_charges>
<tpsdata>
<guaranteed_quote>Yes</guaranteed_quote>
</tpsdata>
</client_specific_illustration>
</product>
<document_out type="Client Specific Illustration">
<print_requirements>
<distribution_method>Web Hosted</distribution_method>
<web_host_format>PDF</web_host_format>
</print_requirements>
</document_out>
</application>
</m_content>
</message>
Below is the xslt that I have tried, but I am not getting the expected output as the note/reason element is not getting removed.
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:o="http://www.origoservices.com" xmlns:dp="http://www.datapower.com/extensions" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:date="http://exslt.org/dates-and-times" version="1.0" extension-element-prefixes="dp" exclude-result-prefixes="fn date">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="o:m_content/o:application/o:product/o:client_specific_illustration/o:note[../../../../../o:m_control/o:initiator_id='TEX']">
</xsl:template>
</xsl:stylesheet>
Could anyone please let me know, where am I comiting mistake?
Regards.
Just have a variable to store the initiator_id. As below:
<xsl:variable name="test" select="o:message/o:m_control/o:initiator_id"/>
Then, test the note node
<xsl:template match="o:note[parent::o:client_specific_illustration]">
<xsl:choose>
<xsl:when test="$test='Dummy'"></xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
The complete stylesheet therefore is:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:o="http://www.origoservices.com" xmlns:dp="http://www.datapower.com/extensions"
xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:date="http://exslt.org/dates-and-times"
version="1.0" extension-element-prefixes="dp" exclude-result-prefixes="fn date">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="test" select="o:message/o:m_control/o:initiator_id"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="o:note[parent::o:client_specific_illustration]">
<xsl:choose>
<xsl:when test="$test='Dummy'"></xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
as an alternative, you can just use
<xsl:template match="o:m_content[preceding-sibling::o:m_control/o:initiator_id='Dummy']/o:application/o:product/o:client_specific_illustration/o:note"/>
I am an admitted novice with XSLT and am looking for some direction. I have the follow (simplified) XML input data. I want to take the underlying data and apply it to AccountExternalSystemId or flatten it out.
<?xml version="1.0" ?>
<ns:CustomObject3WS_CustomObject3QueryPage_Output xmlns:ns="urn:crmondemand/ws/customobject3/10/2004">
<ns:LastPage>true</ns:LastPage>
<ListOfCustomObject3 xmlns="urn:/crmondemand/xml/customObject3">
<CustomObject3>
<AccountExternalSystemId>A000008351</AccountExternalSystemId>
<ListOfAccount>
<Account>
<AccountId>AAXA-H72YN</AccountId>
<ExternalSystemId>100000000002795</ExternalSystemId>
<Name>CATERPILLAR INC [100000000002795]</Name>
</Account>
<Account>
<AccountId>ADOA-3BAK0F</AccountId>
<ExternalSystemId>A000008351</ExternalSystemId>
<Name>CATERPILLAR</Name>
</Account>
</ListOfAccount>
</CustomObject3>
<CustomObject3>
<AccountExternalSystemId>100000000001059</AccountExternalSystemId>
<ListOfAccount>
<Account>
<AccountId>AAXA-H0B7N</AccountId>
<ExternalSystemId>100000000001059</ExternalSystemId>
<Name>SERV SA [100000000001059]</Name>
</Account>
</ListOfAccount>
</CustomObject3>
</ListOfCustomObject3>
I am applying the following XSL to the data:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="*:CustomObject3WS_CustomObject3QueryPage_Output"/>
</xsl:template>
<xsl:template match="*:CustomObject3WS_CustomObject3QueryPage_Output">
<xsl:copy>
<xsl:apply-templates select="*:LastPage"/>
<xsl:apply-templates select="*:ListOfCustomObject3"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*:ListOfCustomObject3">
<xsl:copy>
<xsl:apply-templates select="*:CustomObject3"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*:CustomObject3">
<xsl:variable select="*:AccountExternalSystemId" name="AccountExternalSystemId"/>
<xsl:copy>
<xsl:for-each select="*:ListOfAccount/*:Account">
<xsl:element name="AccountId" namespace="urn:/crmondemand/xml/customObject3"><xsl:value-of select="substring(*:AccountId,1,15)"/></xsl:element>
<xsl:element name="AccountName" namespace="urn:/crmondemand/xml/customObject3"><xsl:value-of select="substring(*:Name,1,255)"/></xsl:element>
<xsl:element name="AccountExternalSystemId" namespace="urn:/crmondemand/xml/customObject3"><xsl:value-of
select="substring($AccountExternalSystemId,1,64)"/></xsl:element>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
and here is my result (you can see that CustomObject3 is not properly ended (as there should be 2) in the first example. Not sure if my approach is the best way to accomplish what I need to do:
<?xml version="1.0" encoding="UTF-8"?>
<ns:CustomObject3WS_CustomObject3QueryPage_Output>
<ns:LastPage>true</ns:LastPage>
<ListOfCustomObject3 xmlns="urn:/crmondemand/xml/customObject3">
<CustomObject3>
<AccountId>AAXA-H72YN</AccountId>
<AccountName>CATERPILLAR INC [100000000002795]</AccountName>
<AccountExternalSystemId>A000008351</AccountExternalSystemId>
<AccountId>ADOA-3BAK0F</AccountId>
<AccountName>CATERPILLAR</AccountName>
<AccountExternalSystemId>A000008351</AccountExternalSystemId>
</CustomObject3>
<CustomObject3>
<AccountId>AAXA-H0B7N</AccountId>
<AccountName>SERV SA [100000000001059]</AccountName>
<AccountExternalSystemId>100000000001059</AccountExternalSystemId>
</CustomObject3>
</ListOfCustomObject3>
The desired output would be:
<?xml version="1.0" encoding="UTF-8"?>
<ns:CustomObject3WS_CustomObject3QueryPage_Output>
<ns:LastPage>true</ns:LastPage>
<ListOfCustomObject3 xmlns="urn:/crmondemand/xml/customObject3">
<CustomObject3>
<AccountId>AAXA-H72YN</AccountId>
<AccountName>CATERPILLAR INC [100000000002795]</AccountName>
<AccountExternalSystemId>A000008351</AccountExternalSystemId>
</CustomObject3>
<CustomObject3>
<AccountId>ADOA-3BAK0F</AccountId>
<AccountName>CATERPILLAR</AccountName>
<AccountExternalSystemId>A000008351</AccountExternalSystemId>
</CustomObject3>
<CustomObject3>
<AccountId>AAXA-H0B7N</AccountId>
<AccountName>SERV SA [100000000001059]</AccountName>
<AccountExternalSystemId>100000000001059</AccountExternalSystemId>
</CustomObject3>
Remark note that the output in your question presents a prefix (ns:) not bound to any namespace declaration.
Look at this direction:
where identity.xsl is the well known Identity Transformation
default namespaces are handled in a simpler way
produced output has the correct namespace declarations
[XSLT 2.0]
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns="urn:/crmondemand/xml/customObject3"
xpath-default-namespace="urn:/crmondemand/xml/customObject3">
<xsl:output indent="yes"/>
<xsl:include href="identity.xsl"/>
<xsl:template match="CustomObject3">
<xsl:apply-templates select="ListOfAccount/Account"/>
</xsl:template>
<xsl:template match="Account">
<CustomObject3>
<xsl:apply-templates select="AccountId|Name"/>
<xsl:copy-of select="../../AccountExternalSystemId"/>
</CustomObject3>
</xsl:template>
<xsl:template match="Name">
<xsl:element name="Account{name()}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
gives wanted output (with correct namespace declarations):
<ns:CustomObject3WS_CustomObject3QueryPage_Output xmlns:ns="urn:crmondemand/ws/customobject3/10/2004">
<ns:LastPage>true</ns:LastPage>
<ListOfCustomObject3 xmlns="urn:/crmondemand/xml/customObject3">
<CustomObject3>
<AccountId>AAXA-H72YN</AccountId>
<AccountName>CATERPILLAR INC [100000000002795]</AccountName>
<AccountExternalSystemId>A000008351</AccountExternalSystemId>
</CustomObject3>
<CustomObject3>
<AccountId>ADOA-3BAK0F</AccountId>
<AccountName>CATERPILLAR</AccountName>
<AccountExternalSystemId>A000008351</AccountExternalSystemId>
</CustomObject3>
<CustomObject3>
<AccountId>AAXA-H0B7N</AccountId>
<AccountName>SERV SA [100000000001059]</AccountName>
<AccountExternalSystemId>100000000001059</AccountExternalSystemId>
</CustomObject3>
</ListOfCustomObject3>
</ns:CustomObject3WS_CustomObject3QueryPage_Output>