Solved

XSLT namespace

Posted on 2008-10-28
3
980 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks alot :-)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now