W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2002

Re: XSL and XML schema

From: Jeni Tennison <jeni@jenitennison.com>
Date: Mon, 4 Feb 2002 14:07:12 +0000
Message-ID: <30616009044.20020204140712@jenitennison.com>
To: Mani Doraisamy <MDoraisamy@SELECTICA.com>
CC: xmlschema-dev@w3.org
Hi Mani,

> Right now i am putting the list of values as an attribute of that
> node separated by | symbol.
> <icecream domain="vanilla|chocolate|strawberry">chocolate</icecream>
> Then i use xsl substring to parse the attribute value and show it in 
> the select box.
> Can you suggest me a better alternative which avoids
> overhead/cumbersome coding. (How about inline xml schema ?)

What I was thinking was that you had a schema that looked like:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="icecream">
    <xs:restriction base="xs:token">
      <xs:enumeration value="vanilla" />
      <xs:enumeration value="chocolate" />
      <xs:enumeration value="strawberry" />


And then an instance like:

<icecream xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

With that, you could get hold of the list with something like:

<xsl:variable name="schema"
  select="document(/*/@xsi:noNamespaceSchemaLocation)/xs:schema" />

<xsl:template match="icecream">
  <xsl:variable name="declaration"
                select="$schema/xs:element[@name = 'icecream']" />
    <xsl:for-each select="$declaration/xs:simpleType/xs:restriction
      <option><xsl:value-of select="@value" /></option>

Note, though, that this depends on you knowing what the structure of
the schema looks like. In XML Schema terms, a schema that looks like:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="icecream" type="icecreamType" />

<xs:simpleType name="icecreamType">
  <xs:restriction base="xs:token">
    <xs:enumeration value="vanilla" />
    <xs:enumeration value="chocolate" />
    <xs:enumeration value="strawberry" />


is basically equivalent, but the XSLT to get hold of the enumerated
values would look quite different. In the general case, the XSLT can
get very complicated - you need to take into account includes and
imports and redefines as well. But if you have control over the XML
Schema it's viable.

Naturally, you could have the schema inline if you wanted - it would
just mean changing the way you set the $schema variable.



Jeni Tennison
Received on Monday, 4 February 2002 09:12:14 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:14:58 UTC