Hi

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.

 

Examples:

   - <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.

:-)

 

Thanks,

Rob

 

===== 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"

    xmlns:saxon="http://saxon.sf.net/"

    version="2.0"

    exclude-result-prefixes="#all">

    <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:variable>

       

        <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"

            doctype-system="concept.dtd"

            exclude-result-prefixes="#all"

            encoding="UTF-8">

            <concept id="{name}">

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

                <shortdesc>FIXME</shortdesc>

                <conbody>

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

                </conbody>

            </concept>

        </xsl:result-document>

    </xsl:template>

   

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

        <xsl:copy>

            <xsl:apply-templates/>

        </xsl:copy>

    </xsl:template>

   

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

</xsl:stylesheet>

 

===== 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"

    xsi:noNamespaceSchemaLocation="http://internal.corporate.com/intranet/generictopic.xsd">

    <name>agent-debugging</name>

    <title>Agent Debugging Title</title>

    <tracking>

        <status>In progress</status>

        <history>

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

        </history>

    </tracking>

   

            <section>

        <title>First Section</title>

        <ul>

            <li><p>first</p></li>

            <li><p>third</p>

            </li>

            <li><p>more</p></li>

        </ul>

        <p>Some more verbiage</p>

    </section>

    <section>

        <title>More verbal guff</title>

        <p>Rainbow extra.</p>

    </section>

</topic>

 

===== 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

 

:xsl_error

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

set SAXON_FILE=

===== 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