xsl-list
[Top] [All Lists]

RE: Replacing DTD reference with xsd reference

2003-04-02 01:20:51
Hi,

So I have:

<?xml version="1.0"?>
<!DOCTYPE trap SYSTEM "./trap.dtd">

<trap>
  ....
</trap>

The result should be:

<?xml version="1.0"?>
<trap xmlns="mynamespace.uri" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
      xsi:schemaLocation="mynamespace.uri trap.xsd">
   ....
</trap>

Because copy-of select copies also the namespace, this is not 
an option for
me (because I want to transform from no namespace into 
mynamespace.uri). Is
there a good way to do this with XSLT, or should I better use 
a script for
transforming my xml files ?

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns="mynamespace.uri">

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="*" priority="1">
  <xsl:element name="{name()}">
    <xsl:if test="not(parent::*)">
      <xsl:attribute name="xsi:schemaLocation"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
        <xsl:value-of select="document('')/*/namespace::*[string-length(name()) 
= 0]" />
        <xsl:text> trap.xsd</xsl:text>
      </xsl:attribute>      
    </xsl:if>
    <xsl:apply-templates select="@*|node()" />
  </xsl:element>
</xsl:template>

</xsl:stylesheet>

Cheers,

Jarno - Assemblage 23: Naked (God Module RMX - 125 BPM)

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>