[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: adding element in with general namespace prefix

Subject: Re: adding element in with general namespace prefix
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Wed, 08 Feb 2012 22:16:00 +0000
Re:  adding element in with general namespace prefix
If I could clarify Wendell's response a little: XSLT 1.0 in general allows the XSLT processor (or more specifically, the serializer) to use whatever prefixes it wants - though in practice, processors only take advantage of this in edge cases. XSLT 2.0 makes the choice of prefix predictable in the vast majority of cases: for example if you have a literal result element <p:xyz> in the stylesheet, then the prefix p will be used in the output. The reason for this change is two-fold: firstly, XML is designed to be human-readable, and prefixes matter to human readers. Secondly, prefixes can be used in content, for example the infamous xsi:type="my:ownType". This only works if there is a declaration for the prefix "my" in the document, so the XSLT author needs to be able to guarantee that "my" will not be replaced by "your".

Michael Kay
Saxonica


On 08/02/2012 22:01, Wendell Piez wrote:
Ram,

Maybe you want to use xsl:copy, which may do better for you. Most processors, when copying an element, will use the same prefix as the input document uses.

Or it may not: as Ken says, processors are not obliged to respect prefixes since a prefix is not properly part of the name, as formally defined; it is only a (local) binding mechanism.

If you are answering a requirement from a partner who does not understand this, you can, in XSLT 2.0, go to considerably more work to construct elements with namespaces, names and their prefixes generated dynamically, using XPath functions such as name(), prefix-from-QName(), and namespace-uri-for-prefix(). An XSLT stylesheet could generate a new header using whatever prefix the input uses, whatever it is -- although such a stylesheet will look pretty mysterious to the uninitiated.

But this is not trivial to do, and a lot of trouble to go to for something that matters only because someone thinks it matters. Even worse, if you are addressing a set of requirements that have never been articulated, which you have only because someone at some point might be unhappy about something ... well. That's a difficult problem to solve.

Cheers,
Wendell

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.