Solved

XSLT namespace

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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

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ā€¦
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to count occurrences of each item in an array.

696 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