[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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


Subject: Re: [xsl] Cannot include namespaces [XSLT 1.0] xsltproc
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Wed, 25 Aug 2010 09:07:23 +0100

You haven't shown us the DTD, but if it changes the behaviour of the transformation, then my guess would be it's one of those DTDs that adds default namespace declarations to elements. These DTDs were designed by the devil to make XSLT programmers go insane.

Michael Kay
Saxonica




On 25/08/2010 07:30, pankaj.c@xxxxxxxxxxxxxxxxxx wrote:
Thanks David and Michael for looking into this. I tried using your
suggestions but seems to be I found something which I didn't knew about.
May be something related with processor or may be I am so dumb ...... too
tired to understand. I just tried doing something below:
Michael I just tried the below sample test for more brevity so that there
will be confusion now.

I tried using David's suggestion

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

But the output is same. Secondly is this mean I have to include namespace
declaration to every element where I want to use aid:pstyle etc. I mean

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

That will too much of coding. When there is no declaration and no external
entity is there (for instance&dagger;) I do not find any difference in
above and below.

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


SAMPLE TEST ============ Here What I tried:

Input XML
======
<?xml version="1.0" encoding="UTF-8"?>
<chapter xmlns:ce=" http://www.elsevier.com/xml/common/dtd">
<ce:title>XXXXXX</ce:title>
<ce:section>
<ce:section-title>This is section title</ce:section-title>
<ce:section>
<ce:section-title>This is section title continue</ce:section-title>
<ce:para>This is para 1.</ce:para>
</ce:section>
</ce:section>
<ce:section>
<ce:section-title>This is section title</ce:section-title>
<ce:para>This is para 2.</ce:para>
<ce:section>
<ce:section-title>This is section title regular</ce:section-title>
<ce:para>This is para 3.</ce:para>
</ce:section>
</ce:section>
</chapter>


Stylesheet: ========

<?xml version="1.0" encoding="UTF-8" ?>
<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:output method="xml" indent="yes"/>


<!-- first template copies input to output --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>

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

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


<xsl:template match="chapter/ce:section/ce:section/ce:section-title"> <xsl:copy> <xsl:choose> <xsl:when test="name(parent::ce:section/preceding-sibling::*[1])='ce:section-title'"> <xsl:attribute name="aid:pstyle">H2_continue</xsl:attribute> </xsl:when> <xsl:when test="name(parent::ce:section/preceding-sibling::*[1])='ce:para'"> <xsl:attribute name="aid:pstyle">H2</xsl:attribute> </xsl:when> <xsl:otherwise> <xsl:attribute name="aid:pstyle">H2</xsl:attribute> </xsl:otherwise> </xsl:choose> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet>

Output XML
=======
<?xml version="1.0"?>
<!-- New document created with EditiX at Fri Aug 06 11:20:17 IST 2010 -->
<?xml-stylesheet type="text/xsl" href="section.xsl"?><chapter xmlns:ce="
http://www.elsevier.com/xml/common/dtd" xmlns:aid="
http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="
http://ns.adobe.com/AdobeInDesign/5.0/" aid:pstyle="" aid5:tableStyle="">
<ce:title aid:pstyle="Chap title">XXXXXX</ce:title>
<ce:section>
<ce:section-title>This is section title</ce:section-title>
<ce:section>
<ce:section-title aid:pstyle="H2_continue">This is section title
continue</ce:section-title>
<ce:para>This is para 1.</ce:para>
</ce:section>
</ce:section>
<ce:section>
<ce:section-title>This is section title</ce:section-title>
<ce:para>This is para 2.</ce:para>
<ce:section>
<ce:section-title aid:pstyle="H2">This is section title
regular</ce:section-title>
<ce:para>This is para 3.</ce:para>
</ce:section>
</ce:section>
</chapter>

Perfect the way I wanted.

Now if I include<ce:sup>&dagger;</ce:sup>  in ce:title for Instance
<ce:title>XXXXXX<ce:sup>&dagger;</ce:sup></ce:title>

nothing happens as of course DTD is not declared and I get the missing
entity declaration error. If I declare DTD on top like below:
<!DOCTYPE chapter SYSTEM
"/Applications/Pankaj/InDesign_DTD/ELSEVIER_BOOKS/book521.dtd"[]>

<!-- XML with Entity Dagger -->

<?xml version="1.0"?>
<!-- New document created with EditiX at Fri Aug 06 11:20:17 IST 2010 -->
<chapter xmlns:ce=" http://www.elsevier.com/xml/common/dtd" xmlns="
http://www.elsevier.com/xml/bk/dtd" xmlns:xlink="
http://www.w3.org/1999/xlink" version="5.2" xml:lang="en"
docsubtype="chp">
<ce:title>XXXXXX<ce:sup loc="post">&#x2020;</ce:sup></ce:title>
<ce:section view="all">
<ce:section-title>This is section title</ce:section-title>
<ce:section view="all">
<ce:section-title>This is section title continue</ce:section-title>
<ce:para view="all">This is para 1.</ce:para>
</ce:section>
</ce:section>
<ce:section view="all">
<ce:section-title>This is section title</ce:section-title>
<ce:para view="all">This is para 2.</ce:para>
<ce:section view="all">
<ce:section-title>This is section title regular</ce:section-title>
<ce:para view="all">This is para 3.</ce:para>
</ce:section>
</ce:section>
</chapter>

I get the correct out put for&dagger; entity with default attribute
(@loc) added to<ce:sup>  element. But no namespace declarations (aid,
aid5) on root element and even not even on ce:title. Also I get the
"PARSING ERROR" on terminal which says:

parser warning : xmlns:ce: ' http://www.elsevier.com/xml/common/dtd' is
not a valid URI
adobe.com/AdobeInDesign/5.0/" xmlns:ce="
http://www.elsevier.com/xml/common/dtd"

Above is QName Namespaces.

I am transforming using command on Terminal

xsltproc -o /Applications/xml/chapter.xml --noout
/Applications/xml/test.xsl /Applications/xml/chapter.xml

I checked my xslt processor on Terminal which says:

xsltproc -V
Using libxml 20616, libxslt 10112 and libexslt 810
xsltproc was compiled against libxml 20616, libxslt 10112 and libexslt 810
libxslt 10112 was compiled against libxml 20616
libexslt 810 was compiled against libxml 20616

Is it something related with xsltproc processor compatibility or "I am not
using the correct command for transformation using xsltproc". (I am asking
this as I am not regular user of this).

Too big description, just wanted to clarify all the issues.

Any suggestions in this regard will be appreciated.

TIA,
Pankaj







parser warning : xmlns:ce: ' http://www.elsevier.com/xml/common/dtd' is
not a valid URI


Current Thread
Keywords