RE: [xsl] Static type-checker

Subject: RE: [xsl] Static type-checker
From: drkm <darkman_spam@xxxxxxxx>
Date: Fri, 18 Nov 2005 12:47:13 +0100 (CET)
Michael Kay wrote:

> If there are places where Saxon-SA isn't reporting static
> type errors where you think it could do so, please let me
> know.

  I have an intresting case, I think.  Here is my schema:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
               xmlns:my="http://www.fgeogres.org/dummy";
               targetNamespace="http://www.fgeogres.org/dummy";>
      <xs:complexType name="super_list_type">
        <xs:sequence>
          <xs:element ref="my:list" maxOccurs="unbounded"/>
        </xs:sequence>
      </xs:complexType>

      <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="slist" type="my:super_list_type"/>
      <xs:element name="list"  type="my:list_type"/>
      <xs:element name="elem"  type="my:elem_type"/>
    </xs:schema>

  With a simple instance:

    <slist xmlns="http://www.fgeogres.org/dummy";>
      <list>
        <elem>val1</elem>
        <elem>val2</elem>
        <elem>val2</elem>
        <elem>val1</elem>
      </list>
    </slist>

  If I declare a variable hosting a 'list' element, of type
'list_type', Saxon makes some type-checking when I access
the variable.  If I declare a variable hosting an 'slist',
of type 'super_list_type', then I declare a variable hosting
a 'list' element, obtained from the 'slist' variable, Saxon
makes type-checking only if I specify the 'xsl:variable/@as'.

  Here is the XSLT script:

    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                   xmlns:my="http://www.fgeogres.org/dummy";
                   version="2.0">
      <xsl:output method="text"/>

      <xsl:import-schema schema-location="saxon-static-analysis.xsd"
                         namespace="http://www.fgeogres.org/dummy"/>

      <xsl:variable name="list" select="/my:slist/my:list[1]"
                    as="element(*, my:list_type)"/>

      <xsl:template match="/">
        <xsl:value-of select="$list/my:elem[1]"/>
        <xsl:value-of select="$list/my:zorglub[1]"/>
      </xsl:template>
    </xsl:transform>

  On this example, Saxon says:

    Warning: on line 14 of saxon-static-analysis.xsl:
      The complex type list_type does not allow a child element
      named zorglub

  If I replace the variable by:

    <xsl:variable name="slist" select="/my:slist"
                  as="element(*, my:super_list_type)"/>
    <xsl:variable name="list"  select="$slist/my:list[1]"
                  as="element(*, my:list_type)"/>

the result is the same.  But if I omit the '@as', like this:

    <xsl:variable name="slist" select="/my:slist"
                  as="element(*, my:super_list_type)"/>
    <xsl:variable name="list"  select="$slist/my:list[1]"/>

Saxon no lomger emits any warning.  But it knows in a
deterministic way the type of the value contained in the
variable.  Is it a choice?  Is it the way the recommendation
describes type-checking?  Is it a check that will be added
in Saxon?

  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
  • RE: [xsl] Static type-checker
    • drkm - Thu, 17 Nov 2005 17:19:51 +0100 (CET)
      • <Possible follow-ups>
      • drkm - Fri, 18 Nov 2005 12:47:13 +0100 (CET) <=
      • drkm - Fri, 18 Nov 2005 15:25:59 +0100 (CET)
      • drkm - Fri, 18 Nov 2005 15:43:55 +0100 (CET)