cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT help needed namespaces

Former Member
0 Kudos

Hello all

I am trying to get rid of namespaces in the XML document. The document XI is producing looks liek 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> <com:ReferencedOrder xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/">

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

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

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

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

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

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

And I would like the document to look like this

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

<com:IssueDate>2008-10-02</com:IssueDate>

<com:TypeCode>PIE</com:TypeCode>

<main:InvoiceCurrencyCode>USD</main:InvoiceCurrencyCode>

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

<com:ReferencedOrder>

<com:BuyerParty>

<com:DestinationParty>

<com:SellerParty>

<com:TaxTotal>

<com:LegalTotals>

<com:InvoiceLine>

Simply put , XI is including a namespcae for every node <com:ID xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/" schemeID="N/A">0018000562</com:ID>

But i would liek just the node <com:ID schemeID="N/A">0018000562</com:ID>

How can we achieve this , XSLT code plz , or could we do this with mapping , adaopter modules etc ..

Thanks a lot

Sudheer

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

go to

www.w3schools.com

and search....

otherwise if u r using any adapter and specifying documentnamespce...just leave that as blank....

Regards

Rams

Former Member
0 Kudos

Thanks for your responses , I am using this code to remove namespaces

<?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"/>

<xsl:template match="*">

<!-- remove element prefix (if any) -->

<xsl:element name="{local-name()}">

<!-- process attributes -->

<xsl:for-each select="@*">

<!-- remove attribute prefix (if any) -->

<xsl:attribute name="{local-name()}">

<xsl:value-of select="."/>

</xsl:attribute>

</xsl:for-each>

<xsl:apply-templates/>

</xsl:element>

</xsl:template>

</xsl:stylesheet>

This code is completely removing all the namespaces from the document. but i want only namespaces for certain nodes to be removed. how can tweak this code to remove namespaces for certain nodes .

thanks a lot

Sudheer

Former Member
0 Kudos

Hi Sudhir

<xsl:element name="{local-name()}">

This removes the local name i.e value for xmlns for all tags

<xsl:element name="local-name()" namespace="mynamespace.uri">

This you can use to change the local name with the value you need for name space. Use these to resolve as per your structure.

Thanks

Gaurav

Former Member
0 Kudos

Hi Gaurav

I think this code applies to the whole XML document , How can i chose a particular node in the xml document? then I could use your suggested tweak to achieve my result.

Former Member
0 Kudos

simply put my requirement is to change the node which look slike this

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

into

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

How can i achive this using XSLT

Thanks

Sudheer

ik69
Participant
0 Kudos

Hi there,

I posted my solution to the other thread

Regards, Igor.

Former Member
0 Kudos

Hi Use

For

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

into 

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

XSL can do like

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

This will not bring the name space.

in case of hierarchy use

<com:ID schemeID="N/A"><xsl:value-of select="//level1/level2/com:ID"/></com:ID>

where level1 , level 2 are nesting of source XML

Thanks

Gaurav

Edited by: Gaurav Bhargava on Oct 25, 2008 6:49 AM

Answers (4)

Answers (4)

Former Member
0 Kudos

Thank you

Former Member
0 Kudos

Hello Guys , I have another strange problem here ,

If I am manually constructing the file with XSLT , then how can I handle dynamic elements in the file , Fr example say there were 3 InvoiceLine nodes instead of 2 , how can i handle this situation.

Cheers

Sudheer

ik69
Participant
0 Kudos

Hi Sudheer, try:

      <xsl:for-each select="//Invoice/com:InvoiceLine">
            <com:ID>
               <xsl:value-of select="./com:ID"/>
            </com:ID>
      </xsl:for-each>

Regards, Igor

Former Member
0 Kudos

HI Igor

Looks liek this could be an answer for my problem , I am doing all this to get rid of ns0: prefix which XI adds to its messages . I need to replace this 'ns0' with 'com'

My message after mapping is

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

<ns0:Invoice xmlns:main="http://rep.oio.dk/ubl/xml/schemas/0p71/maindoc/" xmlns:com="http://rep.oio.dk/ubl/xml/schemas/0p71/common/" xmlns:ns0="http://rep.oio.dk/ubl/xml/schemas/0p71/pie/" xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance">

+ <ns0:ID schemeID="N/A">0018000562</ns0:ID>+

+ <ns0:IssueDate>2008-10-02</ns0:IssueDate>+

+ <ns0:TypeCode>PIE</ns0:TypeCode>+

+ <ns0:InvoiceCurrencyCode>USD</ns0:InvoiceCurrencyCode>+

+ <ns0:BuyersReferenceID schemeID="EAN">5790001330217</ns0:BuyersReferenceID>+

+ <ns0:ReferencedOrder>+

+ <ns0:BuyersOrderID>sdfsdfsd</ns0:BuyersOrderID>+

+ <ns0:IssueDate>2008-09-30</ns0:IssueDate>+

+ </ns0:ReferencedOrder>+

+ <ns0:BuyerParty>+

+ <ns0:ID schemeID="EAN">5790001330217</ns0:ID>+

+ <ns0:PartyName>+

+ <ns0:Name>Fred the sold to party</ns0:Name>+

+ </ns0:PartyName>+

+ <ns0:BuyerContact>+

+ <ns0:ID>contact person from ARLA</ns0:ID>+

+ <ns0:Name>contact person from ARLA</ns0:Name>+

+ </ns0:BuyerContact>+

+ </ns0:BuyerParty>+

+ <ns0:DestinationParty>+

+ <ns0:ID schemeID="EAN">5790001330217</ns0:ID>+

+ <ns0:PartyName>+

+ <ns0:Name>Fred the sold to party</ns0:Name>+

+ </ns0:PartyName>+

+ <ns0:Contact>+

+ <ns0:ID>ARLA contact person</ns0:ID>+

+ <ns0:Name>ARLA contact person</ns0:Name>+

+ </ns0:Contact>+

+ <ns0:Address>+

+ <ns0:ID>Levering</ns0:ID>+

+ <ns0:Street>14 Easy street</ns0:Street>+

+ <ns0:CityName>north Andover</ns0:CityName>+

+ <ns0:PostalZone>0184500</ns0:PostalZone>+

+ <ns0:Country>+

+ <ns0:Code>NL</ns0:Code>+

+ </ns0:Country>+

+ </ns0:Address>+

+ </ns0:DestinationParty>+

+ <ns0:SellerParty>+

+ <ns0:ID schemeID="EAN">Vendor&apos;s EAN number not implemented</ns0:ID>+

+ <ns0:PartyName>+

+ <ns0:Name>APV SYSTEMS US COMMERCIAL</ns0:Name>+

+ </ns0:PartyName>+

+ <ns0:PartyTaxScheme>+

+ <ns0:CompanyTaxID schemeID="CVR">24730018</ns0:CompanyTaxID>+

+ </ns0:PartyTaxScheme>+

+ </ns0:SellerParty>+

+ <ns0:TaxTotal>+

+ <ns0:TaxTypeCode>VAT</ns0:TaxTypeCode>+

+ <ns0:TaxAmounts>+

+ <ns0:TaxableAmount currencyID="USD">101.53</ns0:TaxableAmount>+

+ <ns0:TaxAmount currencyID="DKK">60.00</ns0:TaxAmount>+

+ </ns0:TaxAmounts>+

+ <ns0:CategoryTotal>+

+ <ns0:RateCategoryCodeID>VAT</ns0:RateCategoryCodeID>+

+ <ns0:RatePercentNumeric>25</ns0:RatePercentNumeric>+

+ <ns0:TaxAmounts>+

+ <ns0:TaxableAmount currencyID="USD">101.53</ns0:TaxableAmount>+

+ <ns0:TaxAmount currencyID="DKK">60.00</ns0:TaxAmount>+

+ </ns0:TaxAmounts>+

+ </ns0:CategoryTotal>+

+ </ns0:TaxTotal>+

+ <ns0:LegalTotals>+

+ <ns0:LineExtensionTotalAmount currencyID="USD">101.53</ns0:LineExtensionTotalAmount>+

+ <ns0:ToBePaidTotalAmount currencyID="USD">101.53</ns0:ToBePaidTotalAmount>+

+ </ns0:LegalTotals>+

+ <ns0:InvoiceLine>+

+ <ns0:ID>000010</ns0:ID>+

+ <ns0:InvoicedQuantity unitCode="ST" unitCodeListAgencyID="n/a">1.000</ns0:InvoicedQuantity>+

+ <ns0:LineExtensionAmount currencyID="DKK">1000.00</ns0:LineExtensionAmount>+

+ <ns0:Item>+

+ <ns0:ID schemeID="n/a">DS1234</ns0:ID>+

+ <ns0:Description>Test material for STO</ns0:Description>+

+ <ns0:BasePrice>+

+ <ns0:PriceAmount currencyID="DKK">1000.00</ns0:PriceAmount>+

+ </ns0:BasePrice>+

+ </ns0:Item>+

+ <ns0:BasePrice>+

+ <ns0:PriceAmount currencyID="DKK">1000.00</ns0:PriceAmount>+

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

+ </ns0:BasePrice>+

+ </ns0:InvoiceLine>+

</ns0:Invoice>

I want to replace ns0: with com:

Is there a simpler way to achieve this other than cosntructing the whole file with XSLT .

Thanks a lot

Sudheer

ik69
Participant
0 Kudos

Hi Sudheer,

based on your requirements, I am not sure if there is an easier way how to do that.

I understand that XSLT mapping suggestion I posted above is more difficult and wearisome but it does its work, doesn't it?

Regards, Igor.

Former Member
0 Kudos

Igor , Your solution works no doubt , just wondered if there was an easier way , maybe functions like replace prefix or something in XSLT to achive this , I am not an XSLT expert , Thanks a lot Igor , I will start the time consuming XSLT construction then ,

Shabarish_Nair
Active Contributor
0 Kudos

another option wud be this approach - http://www.tei-c.org/wiki/index.php/Remove-Namespaces.xsl

prateek
Active Contributor
0 Kudos

Open the message type of ur source structure. There make the option "XML Namespace" as blank and try again.

Regards,

Prateek

Former Member
0 Kudos

Hi Prateek the structure i am using is an example XML file . I am using this file directly in message mapping. And this xml file doesn't have namespace declerations for these nodes.