xsl-list
[Top] [All Lists]

RE: Replacing DTD reference with xsd reference

2003-04-02 02:32:31
Getting rid of the DTD reference is trivial. Adding the XSD reference is
trivial. The only non-trivial part is changing the element names to be
in a different namespace. For that you need a variant of the identity
template:

<xsl:template match="*">
  <xsl:element name="local-name()" namespace="mynamespace.uri">
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

To add the schema reference just add another rule for the top-level
element:

<xsl:template match="/*">
  <xsl:element name="local-name()" namespace="mynamespace.uri"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
    <xsl:attribute name="xsi:schemaLocation">mynamespace.uri
trap.xsd</xsl:attribute>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

Michael Kay
Software AG
home: Michael(_dot_)H(_dot_)Kay(_at_)ntlworld(_dot_)com
work: Michael(_dot_)Kay(_at_)softwareag(_dot_)com 

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Cams Ismael
Sent: 02 April 2003 08:39
To: 'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'
Subject: [xsl] Replacing DTD reference with xsd reference


Hello all,

can somebody provide me some help with the following. I have 
thousands of files that conform to a DTD. Now I have written 
a schema for these files. Therefore a transformation is 
needed for all the files.

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 ?

Kind regards,
Ismaël


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



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



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