cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT namespaces

Former Member
0 Kudos

Hi I am trying to get rid of the extra namespaces on each node . My input file look slike this

<com:ID xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/" schemeID="N/A">0018000562</com:ID>

<com:IssueDate xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">2008-10-02</com:IssueDate>

<com:TypeCode xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">PIE</com:TypeCode>

<main:InvoiceCurrencyCode xmlns:main="http://rep.oio.dk/ubl/xml/schemas/0p71/maindoc/">USD</main:InvoiceCurrencyCode>

<com:BuyersReferenceID xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/" schemeID="EAN">5790001330217</com:BuyersReferenceID>

I want to get rid of the xmlns:com="http....." namespace , but want to keep the prefix com on the node levels. I also don't want to completely gey rid of all the namespaces and prefixes.

Could any one give me the XSLT transformation code to achive this please.

Thanks a lot

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI Igor and Gaurav

Thanks for your responses , I tried what you suggested, the output I got is as below

XSLT :

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">

<xsl:template match="/">

<Invoice>

<com:ID schemeID="N/A">

<xsl:value-of select="com:ID"/>

</com:ID>

</Invoice>

</xsl:template>

</xsl:stylesheet>

Output I got is

<?xml version="1.0" encoding="UTF-8" ?>

- <Invoice xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">

<com:ID schemeID="N/A" />

</Invoice>

My desired output is

<?xml version="1.0" encoding="UTF-8" ?>

- <Invoice xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">

<com:ID schemeID="N/A">0018000562</com:ID>

</Invoice>

The "Value-of select=" isn't working as desired , What could have gone wrong .

Thanks a Lot

Sudheer

ik69
Participant
0 Kudos

Hi Sudheer,

if you are using the file from your previous post you should use following value for select (the absolute xpath to ID element):

<xsl:value-of select="//Invoice/com:ID"/>

Regards, Igor.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Igor

I found that I need to specify all the xmlns values in my XSLT for it to work , I got the result , how I wanted , Thanks a lot , the trouble is the xml file is a long file , so I have to write the XSLT for all of the fields now , Long day

Former Member
0 Kudos

Thats the same what was needed ....anyways was trying the whole thing for you .....but Mr. Igor Kozak came through ...well rest you can come along easily .....you can match the templates also wherever you want ....but what Mr. Igor Kozak did thats the easiest and less cumbersome .......But try not to use XSLT for long mapping as it follows DOM parser so doesnt fit beneficial for larger files ....

Former Member
0 Kudos

Hi Sudheer

The piece of code you have provided that is supposed to be input file , but what kind of input file is that .....anyways you told you wanna get rid of xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/" right !!!! from the the particular piece so your desired output i.e what you want is

<com:ID>0018000562</com:ID> or just say the ID hardcore value

Former Member
0 Kudos

Hi Abhishek

Yes the code i Provided is my input file, I just gave a small snippet of my file , here is the whole file

<?xml version="1.0" encoding="utf-8"?>

<?xml-stylesheet type="text/xsl" href="C:\Documents and Settings\Kumar.Kamepalli\Desktop\ARLA EDI\RemovePrefix.xsl"?>

<Invoice xmlns:main="http://rep.oio.dk/ubl/xml/schemas/0p71/maindoc/" xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/" xmlns="http://rep.oio.dk/ubl/xml/schemas/0p71/pie/">

<com:ID xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/" schemeID="N/A">0018000562</com:ID>

<com:IssueDate xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">2008-10-02</com:IssueDate>

<com:TypeCode xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">PIE</com:TypeCode>

<main:InvoiceCurrencyCode xmlns:main="http://rep.oio.dk/ubl/xml/schemas/0p71/maindoc/">USD</main:InvoiceCurrencyCode>

<com:BuyersReferenceID xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/" schemeID="EAN">5790001330217</com:BuyersReferenceID>

<com:ReferencedOrder xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">

<com:BuyersOrderID>sdfsdfsd</com:BuyersOrderID>

<com:SellersOrderID>SalesOrder number</com:SellersOrderID>

<com:IssueDate>2008-09-30</com:IssueDate>

</com:ReferencedOrder>

<com:BuyerParty xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">

<com:ID schemeID="EAN">5790001330217</com:ID>

<com:PartyName>

<com:Name>Fred the sold to party</com:Name>

</com:PartyName>

<com:BuyerContact>

<com:ID>contact person from ARLA</com:ID>

<com:Name>contact person from ARLA</com:Name>

</com:BuyerContact>

</com:BuyerParty>

<com:DestinationParty xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">

<com:ID schemeID="EAN">5790001330217</com:ID>

<com:PartyName>

<com:Name>Fred the sold to party</com:Name>

</com:PartyName>

<com:Contact>

<com:ID>ARLA contact person</com:ID>

<com:Name>ARLA contact person</com:Name>

</com:Contact>

<com:Address>

<com:ID>Levering</com:ID>

<com:Street>14 Easy street</com:Street>

<com:CityName>north Andover</com:CityName>

<com:PostalZone>0184500</com:PostalZone>

<com:Country>

<com:Code>NL</com:Code>

</com:Country>

</com:Address>

</com:DestinationParty>

<com:SellerParty xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">

<com:ID schemeID="EAN">Vendor's EAN number not implemented</com:ID>

<com:PartyName>

<com:Name>APV SYSTEMS US COMMERCIAL</com:Name>

</com:PartyName>

<com:PartyTaxScheme>

<com:CompanyTaxID schemeID="CVR">24730018</com:CompanyTaxID>

</com:PartyTaxScheme>

</com:SellerParty>

<com:TaxTotal xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">

<com:TaxTypeCode>VAT</com:TaxTypeCode>

<com:TaxAmounts>

<com:TaxableAmount currencyID="USD">101.53</com:TaxableAmount>

<com:TaxAmount currencyID="DKK">60.00</com:TaxAmount>

</com:TaxAmounts>

<com:CategoryTotal>

<com:RateCategoryCodeID>VAT</com:RateCategoryCodeID>

<com:RatePercentNumeric>25</com:RatePercentNumeric>

<com:TaxAmounts>

<com:TaxableAmount currencyID="USD">101.53</com:TaxableAmount>

<com:TaxAmount currencyID="DKK">60.00</com:TaxAmount>

</com:TaxAmounts>

</com:CategoryTotal>

</com:TaxTotal>

<com:LegalTotals xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">

<com:LineExtensionTotalAmount currencyID="USD">101.53</com:LineExtensionTotalAmount>

<com:ToBePaidTotalAmount currencyID="USD">101.53</com:ToBePaidTotalAmount>

</com:LegalTotals>

<com:InvoiceLine xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">

<com:ID>000010</com:ID>

<com:InvoicedQuantity unitCode="ST">1.000</com:InvoicedQuantity>

<com:LineExtensionAmount currencyID="DKK">1000.00</com:LineExtensionAmount>

<com:Item>

<com:ID schemeID="n/a">DS1234</com:ID>

<com:Description>Test material for STO</com:Description>

<com:BasePrice>

<com:PriceAmount currencyID="DKK">1000.00</com:PriceAmount>

</com:BasePrice>

</com:Item>

<com:BasePrice>

<com:PriceAmount currencyID="DKK">1000.00</com:PriceAmount>

<com:BaseQuantity unitCode="ST" unitCodeListAgencyID="n/a">1.000</com:BaseQuantity>

</com:BasePrice>

</com:InvoiceLine>

</Invoice>

From this file I wanna get rid of namespace from the nodes , and i wanna keep the prefix .

Ex: my oputpu node should look liek this

<com:ID schemeID="N/A">0018000562</com:ID>

Hope its clear now . I tried with different codes of XSLT , but couldn't achieve the desired result.

ik69
Participant
0 Kudos

Hi there,

here is an examlpe XSLT for your file for Ivoice ID only, you can update it for other fields easily.


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">
		
		<xsl:template match="/">
		<INVOIC01>
			<com:ID schemeID="N/A"><xsl:value-of select="//Invoice/com:ID"/></com:ID>
		</INVOIC01>
		</xsl:template>
</xsl:stylesheet>

This should return something like


  <?xml version="1.0" encoding="utf-8" ?> 
    <INVOIC01 xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">
      <com:ID schemeID="N/A">0018000562</com:ID> 
  </INVOIC01>

Is that what you want?

Regards,

Igor