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

Innovative stylesheet for XML Schema

  • From: ht@c... (Henry S. Thompson)
  • To: xmlschema-dev@w..., XML Developers List <xml-dev@x...>
  • Date: Fri, 08 Dec 2000 13:59:46 +0000

xml schema stylesheet
I recently saw this stylesheet used in a presentation of work going on 
in the National Health Service here in Scotland by David Brazier, who
kindly gave me permission to distribute it.

He emphasises that it's very much work in progress, but may be a
useful starting point for others setting about similar tasks.  Note in 
particular it does nothing with attribute declarations as it stands.
Suggestions welcome!

ht

<?xml version="1.0" encoding="UTF-8"?>
<!-- Stylesheet for NHSiS Schemas - David Brazier 17/11/00
     Work in progress, free for use as-is.
     (c) Copyright Common Services Agency 2000 -->
<xsl:stylesheet version="1.0"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:xsd="http://www.w3.org/2000/10/XMLSchema">
	<xsl:strip-space elements="*"/>
	<xsl:template match="xsd:schema">
		<html>
			<head>
				<title>Schema: <xsl:value-of select="@targetNamespace"/>
				</title>
			</head>
			<style>
   table { border-collapse: collapse }
   td { vertical-align: top }
   </style>
			<!-- for testing:
   td { border: 1px solid blue; vertical-align: top }
-->
			<body>
				<h1>Schema: <xsl:value-of select="@targetNamespace"/>
				</h1>
				<p>Version: <xsl:value-of select="@version"/>
				</p>
				<xsl:apply-templates/>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="xsd:import">
		<hr/>
		<i>Import Schema <xsl:value-of select="@namespace"/> from 
		<a>
			<xsl:attribute name="href">
				<xsl:value-of select="@schemaLocation"/>
			</xsl:attribute>
			<xsl:value-of select="@schemaLocation"/>
		</a>
		</i>
	</xsl:template>
	<xsl:template match="xsd:element">
		<xsl:if test="..=/">
			<hr/>
		</xsl:if>
		<table>
			<tr>
				<td colspan="2">
					<b>
						<xsl:value-of select="@name"/>
					</b>
					&#32;
					<a>
						<xsl:variable name="prefix" select="substring-before(@type,':')"/>
						<xsl:variable name="ns" select="namespace::*[substring-after(name(.),':')=$prefix]"/>
						<xsl:choose>
							<xsl:when test="$ns=/xsd:schema/@targetNamespace">
								<xsl:attribute name="href">#<xsl:value-of select="substring-after(@type,':')"/></xsl:attribute>
							</xsl:when>
							<xsl:when test="/xsd:schema/xsd:import[@namespace=$ns]">
								<xsl:attribute name="href"><xsl:value-of select="/xsd:schema/xsd:import[@namespace=$ns]/@schemaLocation"/>#<xsl:value-of select="substring-after(@type,':')"/></xsl:attribute>
							</xsl:when>
						</xsl:choose>
						<xsl:value-of select="substring-after(@type,':')"/>
					</a>
					(<xsl:choose>
						<xsl:when test="@minOccurs"><xsl:value-of select="@minOccurs"/></xsl:when>
						<xsl:otherwise>1</xsl:otherwise>
					</xsl:choose>-<xsl:choose>
						<xsl:when test="@maxOccurs"><xsl:value-of select="@maxOccurs"/></xsl:when>
						<xsl:otherwise>1</xsl:otherwise>
					</xsl:choose>)
				</td>
			</tr>
			<tr>
				<td width="25"/>
				<td>
					<xsl:apply-templates select="*"/>
				</td>
			</tr>
		</table>
	</xsl:template>
	<xsl:template match="xsd:simpleType">
		<xsl:if test="..=/">
			<hr/>
		</xsl:if>
		<table>
			<xsl:attribute name="id">
				<xsl:value-of select="@name"/>
			</xsl:attribute>
			<tr>
				<td colspan="2">
					<b>
						<xsl:value-of select="@name"/>
					</b>
					&#32;<xsl:value-of select="@type"/>
				</td>
			</tr>
			<tr>
				<td width="25"/>
				<td>
					<xsl:apply-templates select="*"/>
				</td>
			</tr>
		</table>
	</xsl:template>
	<xsl:template match="xsd:complexType">
		<xsl:if test="..=/">
			<hr/>
		</xsl:if>
		<table>
			<xsl:attribute name="id">
				<xsl:value-of select="@name"/>
			</xsl:attribute>
			<tr>
				<td colspan="2">
					<b>
						<xsl:value-of select="@name"/>
					</b>
					&#32;<xsl:value-of select="@type"/>
				</td>
			</tr>
			<tr>
				<td width="25"/>
				<td>
					<xsl:apply-templates select="*"/>
				</td>
			</tr>
		</table>
	</xsl:template>
	<xsl:template match="xsd:sequence">
		<xsl:if test="..=/">
			<hr/>
		</xsl:if>
		<table>
			<tr>
				<td width="25" style="border-right: 1px solid black"/>
				<td>
					<xsl:apply-templates select="*"/>
				</td>
			</tr>
		</table>
	</xsl:template>
	<xsl:template match="xsd:choice">
		<xsl:if test="..=/">
			<hr/>
		</xsl:if>
		<table>
			<tr>
				<td width="25" style="vertical-align: middle; border-right: double black">
				choice
				</td>
				<td>
					<xsl:apply-templates select="*"/>
				</td>
			</tr>
		</table>
	</xsl:template>
	<xsl:template match="xsd:restriction">
		<xsl:value-of select="substring-after(@base,':')"/>&#32;
		<xsl:apply-templates select="*"/>
	</xsl:template>
	<xsl:template match="xsd:minLength">
		<xsl:value-of select="@value"/> ..
	</xsl:template>
	<xsl:template match="xsd:maxLength">
		<xsl:value-of select="@value"/>
	</xsl:template>
	<xsl:template match="xsd:enumeration">
		"<xsl:value-of select="@value"/>"
		<xsl:apply-templates select="*"/>
	</xsl:template>
	<xsl:template match="xsd:pattern">
		<xsl:value-of select="@value"/>
		<xsl:apply-templates select="*"/>
	</xsl:template>
	<xsl:template match="xsd:annotation">
		<xsl:for-each select="xsd:documentation">
			<small>
				<xsl:value-of select="."/>
			</small>
			<br/>
		</xsl:for-each>
		<xsl:for-each select="xsd:appinfo">
			<small>
				<i>
					<xsl:value-of select="."/>
				</i>
			</small>
			<br/>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>

-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
          W3C Fellow 1999--2001, part-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@c...
		     URL: http://www.ltg.ed.ac.uk/~ht/

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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.