I have the following XML document, decoded from an EDI 856 by Azure Logic Apps:
<ins0:X12InterchangeXml DelimiterSetSerializedData="13:10:-1:42:60:-1:-1:-1:-1"
xmlns:ins0="http://schemas.microsoft.com/BizTalk/EDI/X12/2006/InterchangeXML">
<ns0:ISA
xmlns:ns0="http://schemas.microsoft.com/Edi/X12ServiceSchema">
<ISA01>00</ISA01>
<ISA02></ISA02>
<ISA03>01</ISA03>
<ISA04></ISA04>
<ISA05>ZZ</ISA05>
<ISA06>123456789 </ISA06>
<ISA07>12</ISA07>
<ISA08>9987654321 </ISA08>
<ISA09>180102</ISA09>
<ISA10>2108</ISA10>
<ISA11>U</ISA11>
<ISA12>00400</ISA12>
<ISA13>000000351</ISA13>
<ISA14>0</ISA14>
<ISA15>P</ISA15>
<ISA16><</ISA16>
</ns0:ISA>
<FunctionalGroup DocType="http://schemas.microsoft.com/BizTalk/EDI/X12/2006#X12_00401_856">
<ns0:GS
xmlns:ns0="http://schemas.microsoft.com/Edi/X12ServiceSchema">
<GS01>SH</GS01>
<GS02>123456789</GS02>
<GS03>9987654321</GS03>
<GS04>20180102</GS04>
<GS05>2108</GS05>
<GS06>351</GS06>
<GS07>X</GS07>
<GS08>004010</GS08>
</ns0:GS>
<TransactionSet DocType="http://schemas.microsoft.com/BizTalk/EDI/X12/2006#X12_00401_856">
<ns0:X12_00401_856
xmlns:ns0="http://schemas.microsoft.com/BizTalk/EDI/X12/2006">
<ST>
<ST01>856</ST01>
<ST02>000351</ST02>
</ST>
<ns0:BSN>
<BSN01>00</BSN01>
<BSN02>SID87447</BSN02>
<BSN03>20180102</BSN03>
<BSN04>2108</BSN04>
</ns0:BSN>
<ns0:DTM>
<DTM01>011</DTM01>
<DTM02>20180102</DTM02>
<DTM03>2109</DTM03>
<DTM04>ET</DTM04>
</ns0:DTM>
<ns0:HLLoop1>
<ns0:HL>
<HL01>1</HL01>
<HL03>S</HL03>
<HL04>1</HL04>
</ns0:HL>
<ns0:MEA>
<MEA01>PD</MEA01>
<MEA02>G</MEA02>
<MEA03>9985</MEA03>
<ns0:C001_2>
<C00101>LB</C00101>
</ns0:C001_2>
</ns0:MEA>
<ns0:MEA>
<MEA01>PD</MEA01>
<MEA02>N</MEA02>
<MEA03>9174</MEA03>
<ns0:C001_2>
<C00101>LB</C00101>
</ns0:C001_2>
</ns0:MEA>
<ns0:TD1>
<TD101>CTN90</TD101>
<TD102>55</TD102>
</ns0:TD1>
<ns0:TD5>
<TD501>B</TD501>
<TD502>2</TD502>
<TD503>LODQ</TD503>
<TD504>M</TD504>
</ns0:TD5>
<ns0:TD3>
<TD301>TL</TD301>
<TD303>1</TD303>
</ns0:TD3>
<ns0:REF>
<REF01>BM</REF01>
<REF02>SID87447</REF02>
</ns0:REF>
<ns0:N1Loop1>
<ns0:N1>
<N101>SU</N101>
<N103>92</N103>
<N104>8888</N104>
</ns0:N1>
</ns0:N1Loop1>
</ns0:HLLoop1>
<ns0:HLLoop1>
<ns0:HL>
<HL01>2</HL01>
<HL02>1</HL02>
<HL03>O</HL03>
<HL04>1</HL04>
</ns0:HL>
<ns0:PRF>
<PRF01>2018002A</PRF01>
</ns0:PRF>
<ns0:REF>
<REF01>MH</REF01>
<REF02>50945</REF02>
</ns0:REF>
<ns0:N1Loop1>
<ns0:N1>
<N101>SU</N101>
<N103>92</N103>
<N104>8888</N104>
</ns0:N1>
</ns0:N1Loop1>
</ns0:HLLoop1>
<ns0:HLLoop1>
<ns0:HL>
<HL01>3</HL01>
<HL02>2</HL02>
<HL03>I</HL03>
<HL04>0</HL04>
</ns0:HL>
<ns0:LIN>
<LIN02>BP</LIN02>
<LIN03>58706-02010-00V</LIN03>
<LIN04>RC</LIN04>
<LIN05>S0467</LIN05>
</ns0:LIN>
<ns0:SN1>
<SN102>1029</SN102>
<SN103>EA</SN103>
</ns0:SN1>
</ns0:HLLoop1>
<ns0:HLLoop1>
<ns0:HL>
<HL01>4</HL01>
<HL02>2</HL02>
<HL03>I</HL03>
<HL04>0</HL04>
</ns0:HL>
<ns0:LIN>
<LIN02>BP</LIN02>
<LIN03>61327-0R030-K0V</LIN03>
<LIN04>RC</LIN04>
<LIN05>B0058</LIN05>
</ns0:LIN>
<ns0:SN1>
<SN102>858</SN102>
<SN103>EA</SN103>
</ns0:SN1>
</ns0:HLLoop1>
<ns0:HLLoop1>
<ns0:HL>
<HL01>5</HL01>
<HL02>2</HL02>
<HL03>I</HL03>
<HL04>0</HL04>
</ns0:HL>
<ns0:LIN>
<LIN02>BP</LIN02>
<LIN03>61328-0R030-K0V</LIN03>
<LIN04>RC</LIN04>
<LIN05>B0059</LIN05>
</ns0:LIN>
<ns0:SN1>
<SN102>858</SN102>
<SN103>EA</SN103>
</ns0:SN1>
</ns0:HLLoop1>
<ns0:CTT>
<CTT01>5</CTT01>
</ns0:CTT>
<SE>
<SE01>26</SE01>
<SE02>000351</SE02>
</SE>
</ns0:X12_00401_856>
</TransactionSet>
<ns0:GE
xmlns:ns0="http://schemas.microsoft.com/Edi/X12ServiceSchema">
<GE01>1</GE01>
<GE02>351</GE02>
</ns0:GE>
</FunctionalGroup>
<ns0:IEA
xmlns:ns0="http://schemas.microsoft.com/Edi/X12ServiceSchema">
<IEA01>1</IEA01>
<IEA02>000000351</IEA02>
</ns0:IEA>
I seek to write an XSLT to to transform it and at this point I have:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ins0="http://schemas.microsoft.com/BizTalk/EDI/X12/2006/InterchangeXML"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
xmlns:ns0="http://schemas.microsoft.com/Edi/X12ServiceSchema">
<EDI_Message>
<Mailbox>
<Mailbox_Code>
<xsl:value-of select="normalize-space(/ins0:X12InterchangeXml/ns0:ISA/ISA06/text())" />
</Mailbox_Code>
<Mailbox_Qualifier>
<xsl:value-of select="/ins0:X12InterchangeXml/ns0:ISA/ISA05/text()" />
</Mailbox_Qualifier>
<Destination_Qualifier>
<xsl:value-of select="/ins0:X12InterchangeXml/ns0:ISA/ISA07/text()" />
</Destination_Qualifier>
<Destination_Mailbox>
<xsl:value-of select="normalize-space(/ins0:X12InterchangeXml/ns0:ISA/ISA08/text())"/>
</Destination_Mailbox>
<Destination_Code>
<xsl:value-of select="/ins0:X12InterchangeXml/FunctionalGroup/ns0:GS/GS03/text()" />
</Destination_Code>
<Origin_Code>
<xsl:value-of select="/ins0:X12InterchangeXml/FunctionalGroup/TransactionSet/ns0:X12_00401_856/ns0:HLLoop1/ns0:N1Loop1/ns0:N1/N104/text()" />
</Origin_Code>
<Vendor_Code>
<xsl:value-of select="/ins0:X12InterchangeXml/FunctionalGroup/ns0:GS/GS02/text()" />
</Vendor_Code>
<Supplier_Code />
<Actual_Processor_Duns />
<Transmission_Count>
<xsl:value-of select="normalize-space(/ins0:X12InterchangeXml/ns0:ISA/ISA13/text())"/>
</Transmission_Count>
<Ship_From_Code />
<Mailbox_Status>
<xsl:value-of select="normalize-space(/ins0:X12InterchangeXml/ns0:ISA/ISA15/text())"/>
</Mailbox_Status>
<Seller_Identification_Number />
<Element_Separator>*</Element_Separator>
<Subelement_Separator>
<xsl:value-of select="normalize-space(/ins0:X12InterchangeXml/ns0:ISA/ISA16/text())"/>
</Subelement_Separator>
<Segment_Terminator_ASCII_Code>126</Segment_Terminator_ASCII_Code>
<!--Character separating segments, I guess in this case it is the LF character-->
</Mailbox>
</EDI_Message>
</xsl:template>
Since Azure creates the source document. I cannot really change it, or how it is using namespace declarations. My problem is at this point:
<Origin_Code>
<xsl:value-of select="/ins0:X12InterchangeXml/FunctionalGroup/TransactionSet/ns0:X12_00401_856/ns0:HLLoop1/ns0:N1Loop1/ns0:N1/N104/text()" />
</Origin_Code>
I am not getting a value. Either my XPATH is wrong, or I am running afoul of the Azure document having ns0 used twice, once as
<ns0:ISA
xmlns:ns0="http://schemas.microsoft.com/Edi/X12ServiceSchema">
and then later in the same document as:
<ns0:X12_00401_856
xmlns:ns0="http://schemas.microsoft.com/BizTalk/EDI/X12/2006">
I do not know how to indicate an XPATH for what is, in a pseudo-XPATH
/ins0:X12InterchangeXml[@xmlns:ins0="http://schemas.microsoft.com/BizTalk/EDI/X12/2006/InterchangeXML"]/FunctionalGroup[@DocType="http://schemas.microsoft.com/BizTalk/EDI/X12/2006#X12_00401_856"]/TransactionSet[@DocType="http://schemas.microsoft.com/BizTalk/EDI/X12/2006#X12_00401_856"]/ns0:X12_00401_856[@xmlns:ns0="http://schemas.microsoft.com/BizTalk/EDI/X12/2006"]/ns0:HLLoop1[1]/ns0:N1Loop1/ns0:N1/N104/text()
while also having the XSLT support XPATHs that are basically:
/ins0:X12InterchangeXml[@xmlns:ins0="http://schemas.microsoft.com/BizTalk/EDI/X12/2006/InterchangeXML"]/ns0:ISA[@xmlns:ns0="http://schemas.microsoft.com/Edi/X12ServiceSchema"]/ISA01/text()
In your stylesheet you can use any prefixes you like and need, you don't need to use the same prefixes as the input XML, you only need to make sure you bind a prefix to the same namespace URI as the input element has you want to select. Thus, if you have the same prefix used in the input with different namespace URIs, then, in your XSLT, use a different prefix bound to the second URI and in the XPath use that second prefix where needed e.g. xmlns:ns0="http://schemas.microsoft.com/Edi/X12ServiceSchema" xmlns:ns2="http://schemas.microsoft.com/BizTalk/EDI/X12/2006"
as namespace declarations in the XSLT and then use those prefixes in the XPath expressions.