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

Re: Want to use XSLT to sort an XML Schema

Subject: Re: Want to use XSLT to sort an XML Schema
From: "Joe Fawcett" <joefawcett@xxxxxxxxxxx>
Date: Fri, 15 Feb 2008 15:57:48 -0000
Re:  Want to use XSLT to sort an XML Schema
-------------------------------------------------
From: "Glen Mazza" <glen.mazza@xxxxxxxxx>
Sent: Friday, February 15, 2008 3:49 PM
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject:  Want to use XSLT to sort an XML Schema

Hello,

I have a huge XML Schema file consisting of xs:imports,
xs:simpleTypes, and xs:complexTypes.  It is out of alphabetical order,
making it very difficult to quickly find definitions of needed types.
Also, the simpleTypes are interspersed with the complexTypes, and I
would like to keep them separated as well.

I would like to use XSLT to sort the document, first by imports, then
by simpleTypes, and then by complexTypes, and for each the three
groups, to have them sorted alphabetically.

As for the stylesheet, this is the best I can come up with:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="schema">

   <xsl:for-each select="./import">
        <xsl:sort select="@namespace"/>
        <xsl:apply-templates select="."/>
   </xsl:for-each>

   <xsl:for-each select="./simpleType">
        <xsl:sort select="@name"/>
        <xsl:apply-templates select="."/>
   </xsl:for-each>

   <xsl:for-each select="./complexType">
        <xsl:sort select="@name"/>
        <xsl:apply-templates select="."/>
   </xsl:for-each>

</xsl:template>

<xsl:template match="import">
   <xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="simpleType">
   <xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="complexType">
   <xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>

And it's resulting in a huge blank file.  Oh well.  Does anyone know
what I'm missing here to get this to work?  Also, I'm not really
handling namespaces here, i.e., the elements are actually called
xs:import, xs:simpleType, etc.  What (if anything) do I need to do to
take care of the namespaces as well?

Thanks,
Glen


Elements such as import are in the schema namespace, http://www.w3.org/2001/XMLSchema. So you need to declare this in your XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
and then include the xsd prefix in you Patterns/XPath:


<xsl:template match="xsd:schema">

Joe
http://joe.fawcett.name


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.