I am having a problem converting from one XML vocabulary to another, using Saxon.


My input is schema-based.

My output is DTD-based (DITA).


Saxon keeps sticking the namespace attribute (as follows):

  - 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'

on all elements, and only those elements, named in an 'xsl:apply-templates' element that has a "select" attribute.



   - <xsl:apply-templates select="section"/>

   - <xsl:apply-templates select="section[1]/preceding-sibling::*"/>


I have tried using the following attribute, and variations:

- exclude-result-prefixes="#all"

That's the best guess Google turned up for me.


Tested on Saxon9he.jar, downloaded today.

Problem first encountered on Saxon 9.1.

I am working on Windows XP.

My Java is:  Oracle Java - "1.6.0_24"


I expect it's some simple namespace thing that I missed.

What have I missed?

What terms should I have been searching the interwebs with?


Workaround that creates a big mess, although it works and could be automated:

 - remove the "xmlns:xsi" and "xsi:noNamespaceSchemaLocation" attributes from the top level element (<topic>, in the sample)

   of all the source documents before processing.


A 'fairly' short sample follows. You might want to exclude it from replies.






===== Sample XSL code, used as file "convert2dita.xsl":

<?xml version="1.0" encoding="UTF-8"?>

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




    <xsl:output method="xml" indent="yes"/>


    <xsl:param name="xml-file"/>


    <xsl:template match="topic">

        <xsl:variable name="dita-file" >

            <xsl:value-of select="concat( substring-before( $xml-file,'.xml' ),'.dita' )"/>



        <xsl:message select="concat('Input  XML  file: ', $xml-file)"/>

        <xsl:message select="concat('Output DITA file: ', $dita-file)"/>


        <xsl:result-document href="{$dita-file}"

            doctype-public="-//OASIS//DTD DITA Concept//EN"




            <concept id="{name}">

                <title><xsl:value-of select="title"/></title>



                    <xsl:apply-templates select="section" exclude-result-prefixes="#all"/>






    <xsl:template match="section | ul | li | p | title">






    <xsl:template match="topic/name"/>



===== Sample data - used as file "source-w-schema.xml":

<?xml version="1.0" encoding="UTF-8"?>

<topic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" type="generic-topic"



    <title>Agent Debugging Title</title>


        <status>In progress</status>


            <revision>01a19May09 Converted from Frame by script.</revision>





        <title>First Section</title>







        <p>Some more verbiage</p>



        <title>More verbal guff</title>

        <p>Rainbow extra.</p>




===== Sample batch file to demonstrate my command line, used as file "convert2dita.bat":

@echo off

: This script runs the xsl script to convert a single SPFE file to DITA


: set variables

set xsl_name=convert2dita.xsl

set xsl=%~dp0%xsl_name%

set SAXON_FILE=C:\tools\bin\saxon9.4.0.3\saxon9he.jar


    echo --- start debugging ---

    echo basic command - %0

    echo path of cmd   - %~dp0

    echo the xsl file! - %xsl%

    echo --- debugging end ---


@echo on

java -cp "%SAXON_FILE%" net.sf.saxon.Transform -s:%1 -xsl:%xsl% xml-file=%1

@echo off


if errorlevel 1 goto xsl_error

goto end



echo .

echo  Error returned, probably by Saxon (XSL): %errorlevel%

echo .

echo  If you can't see how to fix the problem yourself,

echo  then please report any messages displayed ABOVE or BELOW this message.

echo .




===== End of all the sample files




Rob Echlin, Documentation Systems Architect, Wind River
+1.613.270.5796 | Skype: rob.echlin.wr | robert.echlin@windriver.com

WR Jive - https://communities.windriver.com/people/rechlin