?
Solved

XSLT namespace

Posted on 2008-10-28
3
Medium Priority
?
997 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
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).
Suggested Courses

770 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