xsl-list
[Top] [All Lists]

RE: Static type-checker

2005-11-18 06:36:33
It's always a good idea to declare the types of your variables explicitly.
Saxon will infer a type for the variable from the select expression if it
can do so without contextual analysis, but it won't go chasing around the
houses to do it. Apart from anything else, there's a danger that the
inferences become circular. However, you can expect that Saxon will
gradually get smarter in its checking in future releases.

The XSLT spec doesn't require any static type checking, and in fact the use
of a path expression like $list/my:zorglub[1] is not an error (which is why
Saxon's message is only a warning). The result of the expression is
well-defined, it is an empty sequence. Warnings are entirely
implementation-defined.

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



-----Original Message-----
From: drkm [mailto:darkman_spam(_at_)yahoo(_dot_)fr] 
Sent: 18 November 2005 11:47
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Static type-checker

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 
Téléchargez cette version sur http://fr.messenger.yahoo.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--