Re: [xsl] create XSLT from XML or XSD

Subject: Re: [xsl] create XSLT from XML or XSD
From: "Jacek Radajewski" <jacekrad@xxxxxxxxx>
Date: Mon, 28 Jul 2008 09:02:55 +1000

Sure.  This was not meant to be a complete implementation.  Just a 5
minute hack.  Do you think that this is something that people would
find useful?  I do have little bit of spare time on my hands at the


updated version below

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xs="";

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

  <xsl:template match="/">
    <xsl:element name="xsl:stylesheet">
      <xsl:namespace name="xsl"
      <xsl:attribute name="version" select="'2.0'"/>

  <xsl:template match="xs:import">
    <xsl:comment><xsl:value-of select="@schemaLocation"/> was not

  <xsl:template match="xs:include">
    <xsl:comment><xsl:value-of select="@schemaLocation"/> was not

  <xsl:template match="xs:element[@name]">
    <xsl:comment> auto generated stub for element <xsl:value-of select="@name"/>
    <xsl:element name="xsl:template">
      <xsl:attribute name="match" select="@name"/>
      <xsl:element name="xsl:apply-templates"/>

  <xsl:template match="text()"/>


On Mon, Jul 28, 2008 at 8:40 AM, Michael Kay <mike@xxxxxxxxxxxx> wrote:
>> This is a very basic implementation which simply creates a
>> XSLT stub template for each element declared in your schema
>> (XSD).  It does not cater for elements with the same name in
>> different scope, but can be easily modified to do so.
> It also doesn't cater for xs:include or xs:import or for schema documents
> that have a targetNamespace.
> And I think it would be more helpful to generate stubs that do the same as
> the default template rule, that is, to invoke xsl:apply-templates.
> Michael Kay

Jacek Radajewski

Current Thread