Solved

XSLT namespace

Posted on 2008-10-28
3
983 Views
Last Modified: 2013-11-18
Hi - this an "how-to-solve" question.

The output I want is:

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:bygteq="http://bygteq.dk/integrator" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ccts="urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-2" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:sdt="urn:oasis:names:specification:ubl:schema:xsd:SpecializedDatatypes-2" xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 UBL-Invoice-2.0.xsd">
      <cbc:UBLVersionID>2.0</cbc:UBLVersionID>
      <cbc:CustomizationID>OIOUBL-2.01</cbc:CustomizationID>
      <cbc:ProfileID schemeAgencyID="320" schemeID="urn:oioubl:id:profileid-1.1">Procurement-OrdSimR-BilSim-1.0</cbc:ProfileID>
      <cbc:ID>41056</cbc:ID>



My stylesheet is like this:
            <Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ccts="urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-2" xmlns:sdt="urn:oasis:names:specification:ubl:schema:xsd:SpecializedDatatypes-2" xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 UBL-Invoice-2.0.xsd">
                  <cbc:UBLVersionID>2.0</cbc:UBLVersionID>
                  <cbc:CustomizationID>OIOUBL-2.01</cbc:CustomizationID>
                  <cbc:ProfileID schemeAgencyID="320" schemeID="urn:oioubl:id:profileid-1.1">Procurement-OrdSimR-BilSim-1.0</cbc:ProfileID>
                  <!-- <cbc:ID> -->
                  <!-- <xsl:apply-templates  select="bygteq/Faktura_kreditnota_nummer"/> -->
                  <cbc:ID>
                        <xsl:value-of select="//Faktura_kreditnota_nummer"/>
                  </cbc:ID>

But I would like do do it like this:

      <xsl:template match="/">
            <Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ccts="urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-2" xmlns:sdt="urn:oasis:names:specification:ubl:schema:xsd:SpecializedDatatypes-2" xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 UBL-Invoice-2.0.xsd">
                  <cbc:UBLVersionID>2.0</cbc:UBLVersionID>
                  <cbc:CustomizationID>OIOUBL-2.01</cbc:CustomizationID>
                  <cbc:ProfileID schemeAgencyID="320" schemeID="urn:oioubl:id:profileid-1.1">Procurement-OrdSimR-BilSim-1.0</cbc:ProfileID>
                  <!-- <cbc:ID> -->
                  <xsl:apply-templates  select="bygteq/Faktura_kreditnota_nummer"/>



                  <xsl:template match="Faktura_kreditnota_nummer">
                  <xsl:element name="cbc:ID" namespace="cbc">
                        <xsl:value-of select="//Faktura_kreditnota_nummer"/>
                  </xsl:element>
                  </xsl:template>

But does not give me the output I want. Any surgestions on "how-to-do"

Best regards, Kaj Bromose


0
Comment
Question by:bromose
  • 2
3 Comments
 
LVL 12

Expert Comment

by:jkmyoung
ID: 22822489
Are you sure that your node is located relatively at "bygteq/Faktura_kreditnota_nummer" ?
It may be that you just need to change your first template to
<xsl:template match="/*">

It's hard to tell without seeing the input xml.
0
 
LVL 12

Accepted Solution

by:
jkmyoung earned 250 total points
ID: 22822553
Sorry, reread the question again.
It's probably:
<xsl:element name="cbc:ID" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" >
                        <xsl:value-of select="//Faktura_kreditnota_nummer"/>
</xsl:element>
---
The reason being that xmlns:cbc declaration is only good within it's scope. Once you exit the Invoice node in your stylesheet, the xmlns:cbc node is no longer valid.


Another possible way could be:
<xsl:element name="ID" namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
      <xsl:value-of select="//Faktura_kreditnota_nummer"/>
</xsl:element>
0
 
LVL 3

Author Closing Comment

by:bromose
ID: 31510726
Thanks alot :-)
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question