[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: create XSLT from XML or XSD

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

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

-j

updated version below

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

  <xsl:template match="/">
    <xsl:element name="xsl:stylesheet">
      <xsl:namespace name="xsl"
select="'http://www.w3.org/1999/XSL/Transform'"/>
      <xsl:attribute name="version" select="'2.0'"/>
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="xs:import">
    <xsl:text>&#xA;</xsl:text>
    <xsl:comment><xsl:value-of select="@schemaLocation"/> was not
imported.</xsl:comment>
  </xsl:template>

  <xsl:template match="xs:include">
    <xsl:text>&#xA;</xsl:text>
    <xsl:comment><xsl:value-of select="@schemaLocation"/> was not
included.</xsl:comment>
  </xsl:template>

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

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

</xsl:stylesheet>


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
> http://www.saxonica.com/
>
>



-- 
Jacek Radajewski

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.