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

RE: Static type-checker

Subject: RE: Static type-checker
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 18 Nov 2005 13:36:33 -0000
static type checker
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@xxxxxxxx]
> Sent: 18 November 2005 11:47
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  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
> Tilichargez cette version sur http://fr.messenger.yahoo.com

Current Thread
  • RE: Static type-checker
    • drkm - 17 Nov 2005 16:20:39 -0000
      • <Possible follow-ups>
      • drkm - 18 Nov 2005 11:47:27 -0000
        • Michael Kay - 18 Nov 2005 13:36:55 -0000 <=
      • drkm - 18 Nov 2005 14:26:02 -0000
      • drkm - 18 Nov 2005 14:44:25 -0000
      • drkm - 18 Nov 2005 16:09:54 -0000

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
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.