Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 31st, 2009, 09:04 AM
Authorized User
 
Join Date: May 2006
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to process xml without any namespace

I have two xml files. One has the correct namespace and one xml doesn't have a namespace at all. My xslt expect a namespace on the xml. What is the best way to process the different xml documents.
I think I have to detect the namespace of the document and when it doesn't have the right namespace i have to add a namespace to all the xml nodes and then process the new copied nodes again.. Or is there a better way? If there was a possibility to have one prefix for a specific namespace and an empty namespace...
Can anybody help me what would be the easiest way.

I dont want to change all my rules like:
<xsl:template match="art:myNodeName | myNodeName">
 
Old July 31st, 2009, 09:09 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

With XSLT 2.0 you could use
<xsl:template match="*:foo">
to match elements named 'foo' in any namespace (including no namespace). I don't think there is anything shorter.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old July 31st, 2009, 09:10 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Unfortunately the same 'named' element in a different namespace is a completely different element, so there is no easy way to match two same named nodes other than the way you illustrate.

It would certainly be very easy to write a stylesheet that copied the entire XML document from one namespace to another (i.e. from the 'empty' namespace to your specific one) and pipeline that into your workflow.

If you are using XSLT 2.0 this could be done in one XSLT document, but with XSLT 1.0 I don't think it is possible.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old July 31st, 2009, 09:45 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

My personal preference in this situation is to preprocess the un-namespaced documents to add the namespace, then use the same transformation on both. This is an example of the general approach called "pipeline processing", and its major benefits are that it maximizes reuse and minimizes complexity. Your stylesheet that adds the namespace is a simple module that can be used in many different pipelines; your main transformation is simpler because it isn't trying to do two jobs at once.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
error CS0234: The type or namespace name 'Xml' does not exist in the namespace 'Syste shailesh_kumar C# 2008 aka C# 3.0 8 August 20th, 2009 03:11 AM
Need to convert an existing namespace and add new namespace to the SOAP xml Prabeen XSLT 10 April 28th, 2009 10:18 AM
process all xml files in folder lsantos2000 XSLT 4 November 8th, 2007 01:41 PM
convert XML to XMl - Another Namespace question bonekrusher XSLT 2 July 10th, 2007 07:32 AM
Process XML with Java bonekrusher Java Basics 3 September 27th, 2006 09:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.