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

RE: Xalan Java 2: doesn't seem to output namespaces to

Subject: RE: Xalan Java 2: doesn't seem to output namespaces to result document ...
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 11 Jan 2005 21:38:20 -0000
xsl attribute name xmlns
In XSLT 1.0 there are basically three ways of getting a namespace
declaration into the result tree:

(a) you can copy it from the source document. This happens when you use
xsl:copy to copy an element node or a namespace node

(b) you can copy it from the stylesheet. This happens when you instantiate a
literal result element, unless exclude-result-prefixes is used

(c) you can use the namespace in the name of an element or attribute in the
result tree, in which case the system will generate a declaration of that
namespace automatically

What you can't do is to use xsl:attribute name="xmlns:xyz". Namespaces are
not attributes. The system will assume you want to generate an attribute
with local name xyz, and since it can't use the prefix xmlns (it's
reserved), it will generate a different prefix. I suspect Xalan 1 had a bug
and was allowing you to generate an attribute with the reserved name
xmlns:xyz, which was working by accident because the serializer didn't
notice the error.

It's easier in XSLT 2.0, there is an xsl:namespace instruction to generate a
namespace node explicitly. The simplest workaround in your case is to
generate the xsl:stylesheet using a literal result element, in which case
its namespaces will be copied. You'll need to use xsl:namespace-alias for
this. Note that xsl:namespace-alias *only* affects literal result elements,
if you use it in a stylesheet with no LREs then it's ignored.

Michael Kay
http://www.saxonica.com/



> -----Original Message-----
> From: Ross, Douglas [mailto:DRoss@xxxxxxxxxx] 
> Sent: 11 January 2005 19:17
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Xalan Java 2: doesn't seem to output 
> namespaces to result document ...
> 
> How do I get the namespaces to show up in the output document?
>  
> I use XSLT to create XSLT. 
>  
> When using Xalan version 1, the following xml outputs:
>  
> 	<xsl:stylesheet xmlns:xsl="..." xmlns:bla="...">
>      		<xsl:call-template name="bla:do-something"/>
> 	</xsl:stylesheet>
>  
> And when using Xalan Java 2, I get:
>  
> 	<xsl:stylesheet xmlns:xsl="...">
>       	<xsl:call-template name="bla:do-something"/>
> 	</xsl:stylesheet>
> 
> Note: 'xmlns:bla' is missing!
>  
> Needless to say, the second one fails when I execute it as input -XSL.
>  
> I tried all the things that made sense to me. Add an attribute,
> namespace-alias, and a several other things to no avail. Yes 
> I googled,
> searched, and asked colleagues (begged actually).
>  
> It seems non-triavial to have to change versions of Xalan 
> just for this
> behavior. What gives? Is there an explaination?
>  
> Any help would be appreciated.
>  
> Doug 
>  
> PS Here is a annotated XSLT script:
>  
> <?xml version="1.0" ?>
> <xsl:stylesheet version="1.2" 
>     <!--grasping here 
>       xmlns=http://www.w3.org/TR/REC-xml-names
>     -->
>       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>       xmlns:bla="http://blah-blah"
> >
>  
> <xsl:output method="xml" />
>  
> <!-- didn't help 
> <xsl:namespace-alias stylesheet-prefix="bla" result-prefix="bla"/> 
> -->
>  
> <xsl:template match="/">
>       <xsl:element name="xsl:stylesheet">
>             <xsl:attribute name="version">1.2</xsl:attribute>
>       <!-- didn't help: was ignored unresolve namespace 'xmlns'
>             <xsl:attribute
> name="xmlns:bla">http://developer.kronos.com/application-descr
> iptor/v3/s
> truts-app</xsl:attribute>
>        -->
>             <xsl:apply-templates />
>       </xsl:element>
> </xsl:template>

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.