[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: drkm <darkman_spam@xxxxxxxx>
Date: Fri, 18 Nov 2005 12:47:13 +0100 (CET)
static variable xsl
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

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.