The source xml can come with a different ns prefix for the NativeTrxDetail node in the sample below:
<?xml version="1.0" encoding="UTF-8"?>
<VLog xmlns="http://www.university.com/integration/" xmlns:tri="http://www.university.com/integration/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" GeneratingCodeVersion="2.5.2.0.717" Version="1.0"
xsi:schemaLocation="http://www.university.com/integration/VLog.xsd">
<Header>
<MessageId>08c5a8c055a685d6a71a77</MessageId>
<Timestamp>2016-03-17T16:00:01</Timestamp>
</Header>
<Body>
<tri:Transaction xmlns="http://www.f-arts.org/namespace/" Version="1.0" xsi:type="RetailTransactionStockView">
<RetailStoreID>Bud053</RetailStoreID>
<WorkstationID>1</WorkstationID>
<tri:NativeTrxDetail>
<tri:ApplicationID>POS</tri:ApplicationID>
<tri:OrganizationID>Bud</tri:OrganizationID>
<tri:TillCharacteristics>
<tri:TillDeviceID/>
<tri:TillOperatorID/>
</tri:TillCharacteristics>
</tri:NativeTrxDetail>
<OperatorID>92053</OperatorID>
<CurrencyCode>NZD</CurrencyCode>
<TillID>770</TillID>
<TillSupervisor>92053</TillSupervisor>
<LineItem>
<SequenceNumber>1</SequenceNumber>
<EndDateTime>2016-08-17T16:00:33</EndDateTime>
<tri:NativeLineDetail>
<tri:LineNumber>29</tri:LineNumber>
<tri:LineType>CurrentTransaction</tri:LineType>
<tri:ActionCode>POST_VOID_SALE</tri:ActionCode>
</tri:NativeLineDetail>
<SupplementalData/>
<Command/>
</LineItem>
<Total TotalType="TransactionGrandAmount">
<Amount>-0.55</Amount>
</Total>
<TransactionLink ReasonCode="PostVoid">
<BusinessDayDate>2016-08-17</BusinessDayDate>
</TransactionLink>
</tri:Transaction>
</Body>
</VLog>
I need to change the ns for just NativeTrxDetail though there are other nodes/elements with tri.
Output needed is:
<?xml version="1.0"?>
<ns0:VLog xmlns:b="http://www.f-arts.org/namespace/" xmlns:a="http://www.university.com/integration/" xmlns:ns1="http://www.f-arts.org/namespace/" xmlns:ns0="http://www.university.com/integration/">
<ns0:Header>
<ns0:MessageId>08c5a8c055a685d6a71a77</ns0:MessageId>
<ns0:Timestamp>2016-03-17T16:00:01</ns0:Timestamp>
</ns0:Header>
<ns0:Body>
<ns0:Transaction>
<ns1:RetailStoreID>Bud053</ns1:RetailStoreID>
<ns1:WorkstationID>1</ns1:WorkstationID>
<ns1:NativeTrxDetail>
<ns0:ApplicationID>POS</ns0:ApplicationID>
<ns0:OrganizationID>Bud</ns0:OrganizationID>
</ns1:NativeTrxDetail>
</ns0:Transaction>
</ns0:Body>
</ns0:VLog>
I am able to achieve this by the following:
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="http://www.university.com/integration/" xmlns:ns1="http://www.f-arts.org/namespace/" xmlns:b="http://www.f-arts.org/namespace/">
<xsl:template match="/">
<ns0:VLog xmlns:ns0="http://www.university.com/integration/">
<ns0:Header>
<ns0:MessageId>
<xsl:value-of select="//*[local-name()='MessageId']"/>
</ns0:MessageId>
<ns0:Timestamp>
<xsl:value-of select="//*[local-name()='Timestamp']"/>
</ns0:Timestamp>
</ns0:Header>
<ns0:Body>
<ns0:Transaction>
<ns1:RetailStoreID>
<xsl:value-of select="//*[local-name()='RetailStoreID']"/>
</ns1:RetailStoreID>
<ns1:WorkstationID>
<xsl:value-of select="//*[local-name()='WorkstationID']"/>
</ns1:WorkstationID>
<ns1:NativeTrxDetail>
<ns0:ApplicationID>
<xsl:value-of select="//*[local-name()='ApplicationID']"/>
</ns0:ApplicationID>
<ns0:OrganizationID>
<xsl:value-of select="//*[local-name()='OrganizationID']"/>
</ns0:OrganizationID>
</ns1:NativeTrxDetail>
</ns0:Transaction>
</ns0:Body>
</ns0:VLog>
</xsl:template>
</xsl:stylesheet>
I need to make it such that I don't need to map each element one by one because there are many such nodes in the source xml that would need the same treatment.
I tried the code below but it doesn't work:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tri="http://www.university.com/TE/integration/" xmlns:ns1="http://www.university.com/integration/" xmlns = "http://www.f-arts.org/namespace/" >
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<!-- template to handle elements -->
<xsl:template match="tri:NativeTrxDetail">
<xsl:element name="ns1:{local-name()}">
<xsl:apply-templates select="node() | @*"/>
</xsl:element>
</xsl:template>
<xsl:template match="@tri:NativeTrxDetail">
<xsl:attribute name="ns1:{local-name()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
please help.
Thanks n regards Bhamber