473,805 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HELP - can't add namespace using XSL

I'm trying to validate XML which doesn't include a namespace, so I've
written a schema and I'm attempting to add a namespace to the original
XML using XSLT. The original XML looks like this:

<orderlist>
<order>
<header>
<ordernum>131 3</ordernum>
</header>
</order>
<order>
<header>
<ordernum>131 4</ordernum>
</header>
</order>
</orderlist>

and I would like to be transformed to the following:

<orderlist xmlns="urn:MyOr der-schema">
<order>
<header>
<ordernum>131 3</ordernum>
</header>
</order>
<order>
<header>
<ordernum>131 4</ordernum>
</header>
</order>
</orderlist>

However, every approach I've taken to writing an XSLT to do this
results in a blank namespace for the next-level elements, such as the
following:

<orderlist xmlns="urn:MyOr der-schema">
<order xmlns="">
<header>
<ordernum>131 3</ordernum>
</header>
</order>
<order xmlns="">
<header>
<ordernum>131 4</ordernum>
</header>
</order>
</orderlist>

This empty namespace results in a failed validation. Is there an
approach to adding a namespace to the top-most element of an XML
fragment using XSL such that the namespace of the next-level elements
aren't affected? I really need to be able to validate this XML, so any
help is greatly appreciated.

Thanks in advance

Sep 17 '05 #1
4 1369


n.phelge wrote:
I'm trying to validate XML which doesn't include a namespace, so I've
written a schema and I'm attempting to add a namespace to the original
XML using XSLT. The original XML looks like this:

<orderlist>
<order>
<header>
<ordernum>131 3</ordernum>
</header>
</order>
<order>
<header>
<ordernum>131 4</ordernum>
</header>
</order>
</orderlist>

and I would like to be transformed to the following:

<orderlist xmlns="urn:MyOr der-schema">
<order>
<header>
<ordernum>131 3</ordernum>
</header>
</order>
<order>
<header>
<ordernum>131 4</ordernum>
</header>
</order>
</orderlist>


Should simply work with

<xsl:styleshe et
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns="urn:MyOr der-schema">
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>

where you then need to decide how you want to transform attributes, if
you want to simply copy them you could add

<xsl:template match="@*">
<xsl:copy-of select="." />
</xsl:template>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 17 '05 #2
Tempore 15:32:19, die Saturday 17 September 2005 AD, hinc in foro {comp.text.xml} scripsit n.phelge <n.******@sacbe email.com>:
Is there an
approach to adding a namespace to the top-most element of an XML
fragment using XSL such that the namespace of the next-level elements
aren't affected?


Yes, this is exactly what happens in your example.
The 'xmlns=""' isn't added to the elements; it was already there, by default, hidden.
What you need to do is change the namespace of each and every node in the tree. An identity transform is what you need:

<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<xsl:apply-templates select="node()" mode="put_in_ne w_namespace">
<xsl:with-param name="new_names pace">urn:MyOrd er-schema</xsl:with-param>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="*" mode="put_in_ne w_namespace" priority="1">
<xsl:param name="new_names pace"/>
<xsl:element name="{local-name()}" namespace="{$ne w_namespace}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()" mode="put_in_ne w_namespace">
<xsl:with-param name="new_names pace" select="$new_na mespace"/>
</xsl:apply-templates>
</xsl:element>
</xsl:template>

<xsl:template match="node()" mode="put_in_ne w_namespace">
<xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>
regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Don't send spam. I don't like it and it is illegal.
Sep 17 '05 #3
Tempore 15:42:34, die Saturday 17 September 2005 AD, hinc in foro {comp.text.xml} scripsit Martin Honnen <ma*******@yaho o.de>:
Should simply work with

<xsl:styleshe et
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns="urn:MyOr der-schema">
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>


Hey, that's clever... never thought that would work;-)

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Don't send spam. I don't like it and it is illegal.
Sep 17 '05 #4
Thanks for the quick response, guys! I knew there had to be a
straightforward way of doing it.

Sep 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4359
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing result in any way. Who can help me, I thank you very very much. list.cpp(main program) //-------------------------------------------------------------------------- - #pragma hdrstop #pragma argsused
0
1306
by: Tressa | last post by:
Sorry to be such a novice about this but..... I have a windows service. It contains two separate files. Both have the same namespace name. I need to pass "bDisplay" into the other file. I am getting several errors and not sure why or how to solve them does anyone have any help? How do I access the other file? ServerSocket.cs *This is where the main server start is so the" private bool m_bIsDisplayed = false;" had to go here so it...
0
1872
by: Simon | last post by:
I need call a LoginUser API from MC++ dll, but when I try to call the I have always the same exception: "System.NullReferenceException: Object reference not set to an instance of an object. at LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, Int32 dwLogonType, Int32 dwLogonProvider, IntPtr phToken)" Thanks in advance
1
1257
by: a_deano | last post by:
Hi, I am not totally new to programming for Windows but may have bitten off more than I can chew. My problem is, I would like to install a hook (using SetWindowsHookEx) to monitor mouse movements as I am testing some new hardware we are developing. So, I decided to tackle the .net managed code realm for what I assumed would be a pretty simple job (at least in my c builder exp most likely
14
3335
by: Tiraman | last post by:
Hi , I would like to use nested namespace . I have 3 namespace as dll's : Namespace A Namespace B Namespace C And i want to have some namespace that contain them all , some thing like
5
3292
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time using "F1" help within the VB IDE. Is this expectation achievable In trying to test my help file in the IDE, I have a solution with 2 projects: the DLL and a tester. VB does not look for my help file; instead, it looks for path to my source code...
3
1751
by: James | last post by:
I'm interested in learning C++. I'm not sure exactly what this means. I'm currently a VB.NET/C#.NET programmer (both Windows Forms and ASP.NET). I am totally clueless when it comes to C++. I've tried creating new projects and even that is confusing. I'm unsure of the differences between MFC, ATL, Win32, etc. etc. applications. I don't even know where to begin. If I wanted to write a full screen application with some type of simple...
2
20848
by: AnalogKid17 | last post by:
Keywords: ASP.NET app with VS2005 running on Win2003 with IIS6, and SQL2000 on a WinXP Box I've betting the following for days... it's driving me insane: Server Error in '/' Application. Security Exception Description: The application attempted to perform an operation not
4
2219
by: Brad Isaacs | last post by:
I am working with ASP.NET 2.0 and using an SQL Server 2000 database. I am using Visual Studio 2005 and developing on my Local machine. I am working with Login controls ASP.Configuration, I wanted to move my work and needed to place it on the server. Using VS 2005 , went to BUILD -Publish Web Site Checked the box for :: Alow this precompiled site to be updatable.
3
2315
by: Stephen Torri | last post by:
Below is a class that is suppose to represent a segment of memory or a contents of a binary image (e.g. ELF executable). I have started to read Modern C++ Design and thought the best way to ensure I was understanding the chapter on policy classes was to attempt to apply them to my project. I understand the general concept of policies but I lack the knowledge and wisdom of how to identify them in an existing project. So I figured to get an...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10609
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10360
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.