XSLT Issue - Donot XML Namespace at Element Level. Please He
Posted: Thu Apr 10, 2014 9:22 pm
Input XML:
<MT_Superior_invoice xmlns='urn:abc.com:10'
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<Invoice_recs>
<Invoice_header>
<comp_code>8000</comp_code>
<AP_text>8VXHR820120624</AP_text>
<header_text>003000993020120624</header_text>
<document_dt>20131115</document_dt>
<posting_dt>20131115</posting_dt>
<fiscal_year>2013</fiscal_year>
<document_type>DB</document_type>
<Reference_no>8VXHR8</Reference_no>
<vendor_no>318992</vendor_no>
<amount>6042.48</amount>
<invoice_details>
<Line_num>10</Line_num>
<gl_account>633001</gl_account>
<item_text>DWAIN Cochran</item_text>
<cr_dr_ind>DB</cr_dr_ind>
<tax_code>I1</tax_code>
<tax_jurisdiction>WA1030000</tax_jurisdiction>
<cost_center>801404</cost_center>
<amount>680.0</amount>
</invoice_details>
</Invoice_header>
</Invoice_recs>
</MT_Superior_invoice>
Output needed:
<ns0:MT_Superior_invoice xmlns:ns0='urn:abc.com:10'>
<Invoice_recs>
<Invoice_header>
<comp_code>8000</comp_code>
<AP_text>8VXHR820120624</AP_text>
<header_text>003000993020120624</header_text>
<document_dt>20131115</document_dt>
<posting_dt>20131115</posting_dt>
<fiscal_year>2013</fiscal_year>
<document_type>DB</document_type>
<Reference_no>8VXHR8</Reference_no>
<vendor_no>318992</vendor_no>
<amount>6042.48</amount>
<invoice_details>
<Line_num>10</Line_num>
<gl_account>633001</gl_account>
<item_text>DWAIN Cochran</item_text>
<cr_dr_ind>DB</cr_dr_ind>
<tax_code>I1</tax_code>
<tax_jurisdiction>WA1030000</tax_jurisdiction>
<cost_center>801404</cost_center>
<amount>680.0</amount>
</invoice_details>
</Invoice_header>
</Invoice_recs>
</ns0:MT_Superior_invoice>
XSLT Used:
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="urn:abc.com:10">
<xsl:template match="/">
<ns0:MT_Superior_invoice>
<xsl:copy-of select="ns0:MT_Superior_invoice/ns0:Invoice_recs"/>
</ns0:MT_Superior_invoice>
</xsl:template>
</xsl:stylesheet>
Issue with Above XSLT is its copying xmlns for every element. But I want only at root as shown in Output. Removing ns0 on Copy-of Select not picking any element at all. What change I should do to get the Output shown above?. Any help in the code would be much appreciated as I'm stuck. Thank you.
<MT_Superior_invoice xmlns='urn:abc.com:10'
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<Invoice_recs>
<Invoice_header>
<comp_code>8000</comp_code>
<AP_text>8VXHR820120624</AP_text>
<header_text>003000993020120624</header_text>
<document_dt>20131115</document_dt>
<posting_dt>20131115</posting_dt>
<fiscal_year>2013</fiscal_year>
<document_type>DB</document_type>
<Reference_no>8VXHR8</Reference_no>
<vendor_no>318992</vendor_no>
<amount>6042.48</amount>
<invoice_details>
<Line_num>10</Line_num>
<gl_account>633001</gl_account>
<item_text>DWAIN Cochran</item_text>
<cr_dr_ind>DB</cr_dr_ind>
<tax_code>I1</tax_code>
<tax_jurisdiction>WA1030000</tax_jurisdiction>
<cost_center>801404</cost_center>
<amount>680.0</amount>
</invoice_details>
</Invoice_header>
</Invoice_recs>
</MT_Superior_invoice>
Output needed:
<ns0:MT_Superior_invoice xmlns:ns0='urn:abc.com:10'>
<Invoice_recs>
<Invoice_header>
<comp_code>8000</comp_code>
<AP_text>8VXHR820120624</AP_text>
<header_text>003000993020120624</header_text>
<document_dt>20131115</document_dt>
<posting_dt>20131115</posting_dt>
<fiscal_year>2013</fiscal_year>
<document_type>DB</document_type>
<Reference_no>8VXHR8</Reference_no>
<vendor_no>318992</vendor_no>
<amount>6042.48</amount>
<invoice_details>
<Line_num>10</Line_num>
<gl_account>633001</gl_account>
<item_text>DWAIN Cochran</item_text>
<cr_dr_ind>DB</cr_dr_ind>
<tax_code>I1</tax_code>
<tax_jurisdiction>WA1030000</tax_jurisdiction>
<cost_center>801404</cost_center>
<amount>680.0</amount>
</invoice_details>
</Invoice_header>
</Invoice_recs>
</ns0:MT_Superior_invoice>
XSLT Used:
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="urn:abc.com:10">
<xsl:template match="/">
<ns0:MT_Superior_invoice>
<xsl:copy-of select="ns0:MT_Superior_invoice/ns0:Invoice_recs"/>
</ns0:MT_Superior_invoice>
</xsl:template>
</xsl:stylesheet>
Issue with Above XSLT is its copying xmlns for every element. But I want only at root as shown in Output. Removing ns0 on Copy-of Select not picking any element at all. What change I should do to get the Output shown above?. Any help in the code would be much appreciated as I'm stuck. Thank you.