You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Adrian Sutton <Ad...@Ephox.com> on 2003/08/28 09:03:27 UTC

"Unused" xmlns attributes being lost

Hi all,
My apologies if I'm missing some obvious documentation on this, my brain
seems to work a different way to the xml.apache.org site and I have trouble
finding anything.

I'm trying to use XSLTC to run an XSLT over another XSLT.  In XSLT there are
often times when a prefix is used as part of an attribute value and it must
be defined correctly.  For example:

<xsl:preserve-space elements="xhtml:*"
xmlns:xhtml="http://www.w3.org/1999/xhtml"/>

So for a somewhat contrived (but simple) example of the problem, take the
following stylesheet and run it over itself:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

	<xsl:output method="xml"/>
	<xsl:strip-space elements="*"/>
	<xsl:preserve-space elements="xhtml:*"
xmlns:xhtml="http://www.w3.org/1999/xhtml"/>

	<xsl:template match="*">
		<xsl:copy>
			<xsl:for-each select="@*">
				<xsl:copy-of select="."/>
			</xsl:for-each>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>

You would expect to get effectively that same stylesheet back out, however
what actually comes out is the same stylesheet minux the xmlns:xhtml
declaration which then causes errors when attempting to use it as a
stylesheet (except with XSLTC which seems to ignore xsl:preserve-space).

If I change the template to be just:

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

the xmlns:xhtml declaration is preserved.  I would have thought the two
constructs were equivalent though.

I'm using XSLTC built from XAlan 2.5.1 on Java 1.3.1 on Mac OS X.

Any pointers to what I'm doing wrong and/or how to fix things would be
greatly appreciated.

Thanks in advance,

Adrian Sutton, Software Engineer
Ephox Corporation
www.ephox.com

Re: "Unused" xmlns attributes being lost

Posted by da...@us.ibm.com.



> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>
>            <xsl:output method="xml"/>
>            <xsl:strip-space elements="*"/>
>            <xsl:preserve-space elements="xhtml:*"
> xmlns:xhtml="http://www.w3.org/1999/xhtml"/>
>
>            <xsl:template match="*">
>                        <xsl:copy>
>                                    <xsl:for-each select="@*">
>                                                <xsl:copy-of select="."/>
>                                    </xsl:for-each>
>                                    <xsl:apply-templates/>
>                        </xsl:copy>
>            </xsl:template>
> </xsl:stylesheet>
>
> You would expect to get effectively that same stylesheet back out,
however
> what actually comes out is the same stylesheet minux the xmlns:xhtml
> declaration which then causes errors when attempting to use it as a
> stylesheet (except with XSLTC which seems to ignore xsl:preserve-space).
>
> If I change the template to be just:
>
> <xsl:template match="*">
>            <xsl:copy-of select="."/>
> </xsl:template>
>
> the xmlns:xhtml declaration is preserved.  I would have thought the two
> constructs were equivalent though.

They are not equivalent.  This is a generic XSLT question, so a better
forum for it would be the Mulberry XSL list.  However, a few pointers:

   1. Namespace nodes are not attributes in the XPath data model:

      http://www.w3.org/TR/xpath#data-model

   2. You should take a look at the copy instruction in XSLT for more
   information.  There is even an example of the canonical identity
   transformation stylesheet:

      http://www.w3.org/TR/xslt#copying

Dave