xsl-list
[Top] [All Lists]

Re: [xsl] Cannot include namespaces [XSLT 1.0] xsltproc

2010-08-23 17:34:51
The output seems wrong to me. I can't understand why the xsl:attribute instruction isn't producing an aid:pstyle attribute, which would automatically result in an xmlns:aid namespace declaration being output.

Perhaps it's best to avoid snippets. I ran this stylesheet:

<xsl:stylesheet version="1.0"
    xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/";
    xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/";
    xmlns:ce="http://www.elsevier.com/xml/common/dtd";
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template match="chapter">
<xsl:copy>
<xsl:attribute name="aid:pstyle"/>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

against this source document:

<chapter version="5.2" xml:lang="en" docsubtype="chp" id="c0030"
xmlns:sb="http://www.elsevier.com/xml/bk/dtd";
xmlns:ce="http://www.elsevier.com/xml/common/dtd";>
<ce:title>xxxxx</ce:title>
</chapter>

and got this output (whitespace added for clarity):

<?xml version="1.0" encoding="UTF-8"?>
<chapter xmlns:sb="http://www.elsevier.com/xml/bk/dtd";
                xmlns:ce="http://www.elsevier.com/xml/common/dtd";
                xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/";
aid:pstyle="" version="5.2" xml:lang="en" docsubtype="chp" id="c0030">
  xxxxx
</chapter>

There are some recoverable errors defined in XSLT 1.0 that would entitle a processor to ignore the xsl:attribute instruction (for example, if the name attribute is not a valid QName), but none of them seem to apply here. So in my view, either the stylesheet you are running differs materially from what you have shown us, or there is a bug/nonconformance in your XSLT processor.

However, there is no reason to expect the namespace declaration

xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/";

to appear in your result tree. Namespace declarations are copied from the stylesheet to the result tree only when you use a literal result element. When you use xsl:copy to create an element, it is the namespaces in the source document that are copied. The xmlns:aid in my example appears only because the result tree contains an attribute whose name is in this namespace.

Michael Kay
Saxonica

On 23/08/2010 14:47, pankaj(_dot_)c(_at_)thomsondigital(_dot_)com wrote:
<xsl:stylesheet version="1.0" xmlns:aid="
http://ns.adobe.com/AdobeInDesign/4.0/"; xmlns:aid5="
http://ns.adobe.com/AdobeInDesign/5.0/"; xmlns:ce="
http://www.elsevier.com/xml/common/dtd"; xmlns:xsl="
http://www.w3.org/1999/XSL/Transform";>

My xml snippet:
<chapter version="5.2" xml:lang="en" docsubtype="chp" id="c0030"
xmlns:sb="http://www.elsevier.com/xml/bk/dtd";  xmlns:ce="
http://www.elsevier.com/xml/common/dtd";><ce:title>xxxxx</ce:title>

stylesheet snippet

<xsl:template match="chapter">
<xsl:copy>
<xsl:attribute name="aid:pstyle"/>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--