I've hit a nail with a transformation that used to work fine.

First, a little background: I transform a dependencies.xml file into several
Ant build.xml files using a stylesheet that makes use of the redirect
extension. Worked great (even though the formatting of the generated
build.xml files is horrible!).

The transformation is driven by Ant of course ;-) The source XML document
will start being modified by many developers which do not know its exact
structure. I thus developed a schema for it (dependencies.xsd) collocated to
the source document, and added a validation step (in Ant) of the source
document prior to the transformation. I thus added the following attributes
to my root element:

<module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xsi:noNamespaceSchemaLocation="dependencies.xsd"
        name="tahoe">

(BTW, this document is similar, but not the same, as a GUMP descriptor, and
didn't belong to any namespace).

Adding xsi-related attributes ensured proper validation of the document by
my Ant task (Ant's <xmlvalidate> supports schema validation in CVS only, not
Ant 1.5.1). So far, so good.

The problem I have is that since I added these attributes (/ namespace
declaration), all elements of my source document which are copied as-is to
the generated build.xml files now include an extraneous
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; declarations in them,
and of course Ant is chocking on that...

Here's a fragment of the source document, and a fragment of the generated
build.xml, along the the xsl fragment that did the copy:

  <project ...>
    <sources>
      <include name="com/lgc/infra/viz/**"/>
      <exclude name="com/lgc/infra/viz/fv/**"/>
    </sources>
    <depend project="dep-vecmath"/>
    <depend project="lgc-sc3"/>
  </project>

yields:

<fileset dir="${ds.home}/src" id="sources">

<include xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
name="com/lgc/infra/viz/**"/>

<exclude xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
name="com/lgc/infra/viz/fv/**"/>

</fileset>

from:

  <xsl:template match="project">
    ...
        <fileset id="sources"
                 dir="{'${ds.home}/src'}">
          <xsl:copy-of select="sources/*"/>
        </fileset>
    ...
  </xsl:template>

How can I get rid of these xmlns:xsi declarations showing up every time I
use <xsl:copy-of>???

I tried using exclude-result-prefixes as shown below to no avail (and
several variant thereof):

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:lxslt="http://xml.apache.org/xslt";
                xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
                extension-element-prefixes="redirect"
                exclude-result-prefixes="xsi #default">

I also tried putting my source document in a default namespace to no avail
either. Basically I have no clue why these xmlns:xsi declarations are making
it to the generated files, and how to remove them.

I'm using the Xalan version in JDK 1.4.0_01, with the regular Crimson parser
from the JDK.

Thanks for any help, and sorry for the long winded post. I can provide still
more info if needed ;-) --DD

Reply via email to