RE: [xsl] [XSLT-2.0] Template rules matching elements by type

Subject: RE: [xsl] [XSLT-2.0] Template rules matching elements by type
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 30 Oct 2005 15:24:59 -0000
Running this with Saxon:

java com.saxonica.Transform -val schema-aware.xml schema-aware.xsl

First attempt gives the error message

Error at xsl:import-schema on line 9 of file:/c:/temp/schema-aware.xsl:
  Schema at location schema-aware.xsd has target namespace
"http://www.fgeogres.org/dummy";
  but requested namespace was ""

I corrected that by adding a namespace attribute to the import-schema
declaration. The output is now:

A 'list_type' element: 'list'
An 'elem_type' element: 'elem'
An 'elem_type' element: 'elem'
An 'elem_type' element: 'elem'
An 'elem_type' element: 'elem'

which is presumably what you expected.

The XSLT spec actually specifies what it means to omit the namespace
attribute rather indirectly, by reference to the semantics of xs:import in
the schema specification. The schema spec makes it clear that an absent
namespace attribute is a reference to a "no-namespace" schema. By
implication, XSLT inherits the rule for xs:import (in schema part 2 section
4.2.3):

The appropriate case among the following must be true:
3.1 If there is a namespace attribute, then its 7actual value7 must be
identical to the 7actual value7 of the targetNamespace attribute of [the
imported schema].
3.2 If there is no namespace attribute, then [the imported schema] must have
no targetNamespace attribute

I can't account for Altova's behavior - you'll have to ask them.

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: drkm [mailto:darkman_spam@xxxxxxxx]
> Sent: 30 October 2005 15:03
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] [XSLT-2.0] Template rules matching elements by type
>
>   Hi
>
>   I'm trying the schema features of XSLT 2.0 and XPath 2.0,
> with Altova XML (the only free schema-aware XSLT 2.0
> processor I know).  But I don't succeed for now to write a
> template rule matching elements by type.  Here is a minimal
> example:
>
>     ~> cat schema-aware.xsd
>     <?xml version="1.0" encoding="ISO-8859-1"?>
>
>     <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
>                xmlns:my="http://www.fgeogres.org/dummy";
>                targetNamespace="http://www.fgeogres.org/dummy";
>                elementFormDefault="unqualified"
>                attributeFormDefault="unqualified">
>
>       <xs:complexType name="list_type">
>         <xs:sequence>
>           <xs:element ref="my:elem" maxOccurs="unbounded"/>
>         </xs:sequence>
>       </xs:complexType>
>
>       <xs:simpleType name="elem_type">
>         <xs:restriction base="xs:string">
>           <xs:enumeration value="val1"/>
>           <xs:enumeration value="val2"/>
>         </xs:restriction>
>       </xs:simpleType>
>
>       <xs:element name="list" type="my:list_type"/>
>       <xs:element name="elem" type="my:elem_type"/>
>
>     </xs:schema>
>
>     ~> cat schema-aware.xsl
>     <?xml version="1.0" encoding="ISO-8859-1"?>
>
>     <xsl:stylesheet version="2.0"
>                     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>                     xmlns:my="http://www.fgeogres.org/dummy";>
>
>     <xsl:output method="text"/>
>
>     <xsl:import-schema schema-location="schema-aware.xsd"/>
>
>     <xsl:template match="node()">
>       <xsl:apply-templates/>
>     </xsl:template>
>
>     <xsl:template match="element(*,my:list_type)">
>       <xsl:text>A 'list_type' element: '</xsl:text>
>       <xsl:value-of select="name()"/>
>       <xsl:text>'&#10;</xsl:text>
>       <xsl:apply-templates/>
>     </xsl:template>
>
>     <xsl:template match="element(*,my:elem_type)">
>       <xsl:text>An 'elem_type' element: '</xsl:text>
>       <xsl:value-of select="name()"/>
>       <xsl:text>'&#10;</xsl:text>
>       <xsl:apply-templates/>
>     </xsl:template>
>
>     </xsl:stylesheet>
>
>     ~> cat schema-aware.xml
>     <list xmlns="http://www.fgeogres.org/dummy";>
>       <elem>val1</elem>
>       <elem>val2</elem>
>       <elem>val2</elem>
>       <elem>val1</elem>
>     </list>
>
>     ~> altova-xml /xslt2 schema-aware.xsl /in schema-aware.xml
>
>   Not really what I did excpect.
>
>   Thanks,
>
> --drkm
>
>
>
>
>
>
>
> ______________________________________________________________
> _____________
> Appel audio GRATUIT partout dans le monde avec le nouveau
> Yahoo! Messenger
> Tilichargez cette version sur http://fr.messenger.yahoo.com

Current Thread