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 June 6th, 2007, 12:12 PM
Registered User
 
Join Date: Jun 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic Default Namespace

I've got an incoming XML with a default namespace, and I've written my XSLT for it, explicitly declaring the same namespace and using its prefix in all my xpaths. Like this:

<?xml version="1.0" encoding="UTF-8"?>
<IncomingXML xmlns="http://www.qa.com/blah">
<data>
<d1>data1</d1>
<d2>hello</d2>
<d3>data3</d3>
</data>
<otherdata>
<od1>otherdata1</od1>
<od2>world</od2>
<od3>otherdata3</od3>
</otherdata>
</IncomingXML>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:XXX="http://www.qa.com/blah.rdr" exclude-result-prefixes="XXX">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<GreetingsFromSpace>
<xsl:value-of select="concat(/XXX:IncomingXML/XXX:data/XXX:d2, ' ', /XXX:IncomingXML/XXX:otherdata/XXX:od2)"/>
</GreetingsFromSpace>
</xsl:template>
</xsl:stylesheet>

Now it turns out that in between QA and production, the default namespace on the incoming XML changes to "http://www.prod.com/blah". I don't want to have to maintain a separate XSLT or a second instance of my transform in a different template just for a different namespace. Is there something simple I can change in my current XSLT to handle this?


Thanks!


 
Old June 6th, 2007, 12:53 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Changing a namespace between QA and production is a really bad decision, since it invalidates all the testing done by/in QA. But if you can't get the powers-that-be to acknowledge that, my preferred solution to this kind of problem is pipelining: write a pre-processing transformation that modifies the namespace on the document and does nothing else.

Another option is to preprocess the stylesheet to change the namespace declaration - that is, write a stylesheet to transform the stylesheet. Or even just a Perl script.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 6th, 2007, 04:05 PM
Registered User
 
Join Date: Jun 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I was afraid of that. There was a hack in the original code I'm refactoring to remove the namespace in the incoming string before it was loaded into a document. I thought I'd do things the "right" way, but ... ultimately, it's back to removing the namespace.

Thanks for your thoughts.






Similar Threads
Thread Thread Starter Forum Replies Last Post
XmlWriter and default namespace miguel.ossa XML 11 December 4th, 2008 08:05 AM
default-xpath-namespace stolte XSLT 1 March 19th, 2008 12:49 PM
Default Namespace - XSLT 1.0 Geierwally XSLT 2 July 9th, 2007 11:08 AM
How can I change the default namespace allanhu BOOK: ASP.NET Website Programming Problem-Design-Solution 1 November 1st, 2004 01:15 PM
Default Namespace (where is it?) bekim BOOK: ASP.NET Website Programming Problem-Design-Solution 4 June 12th, 2004 03:50 AM





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