Solved

XSLT namespace

Posted on 2008-10-28
3
987 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

730 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