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

Re: strong typed variable with restriction ?

Subject: Re: strong typed variable with restriction ?
From: Matthieu Ricaud-Dussarget <matthieu.ricaud@xxxxxxxxx>
Date: Wed, 02 Feb 2011 14:06:23 +0100
Re:  strong typed variable with restriction ?
I tried to override the original function with this one :
<xsl:function name="igs:get-css-rule" as="element()*">
<xsl:param name="e" as="element()"/>
<xsl:param name="csspath" as="xs:string"/>
<xsl:param name="mode" as="xs:string"/><!--(override|not-override|both)-->
<xsl:param name="css" as="xs:string"/><!--(csstidy|css)-->
<xsl:sequence select="igs:get-css-rule($e,$csspath,$mode cast as igs:override_mode, $css cast as igs:css_mode)"/>

But as the number of params is the same with the original function, I get a duplicate function error.
Would have been great to be able to discern functions from typed params and not only numbers of param, but so it is...

[offtopic : on the other hand SaxonHE is not schema aware, this is a good argument to get saxonEE , I'll ask my boss !]

Thanks for this last advice Michel, using <xsl:message terminate="yes">...</> would be an acceptable solution for me at this point.

Thanks all for your help,

Le 02/02/2011 13:43, Michel Hendriksen a icrit :
Or add a message in an xsl:otherwise...

<xsl:message terminate="yes|no">

<!-- Content:template -->


On Wed, Feb 2, 2011 at 12:21 PM, Michael Kay<mike@xxxxxxxxxxxx> wrote:
There seem to be two separate questions here.
I have a xsl:function which :
- must return a element()
- has a string param "foobar".

I typed $foobar as xs:string but I'd like to restrict the possible values
to "foo" or "bar".
I know it's possible to define such a constrain in a xsd schema, but is
there a way to do that in xpath2 ?
You can declare a local type in your stylesheet:

<xsl:stylesheet xmlns:fb="urn:local:foobar" ....>

<xs:schema targetNamespace="urn:local:foobar">
<xs:simpleType name="foobarType">
<xs:restriction base="xs:string">
<xs:enumeration value="foo"/>
<xs:enumeration value="bar"/>

<xsl:function name="igs:get-css-rule" as="element()">
<xsl:param name="foobar" as="fb:foobarType"/>

Note that when calling the function, you can't pass a string directly: you
will have to cast ot to fb:foobarType first.

This typing is important because the returned element() is selected from a xsl:choose on $foobar value (with no otherwise) :

My code looks like :
<xsl:function name="igs:get-css-rule" as="element()">
<xsl:param name="foobar" as="xs:string"/>  <!--(foo|bar)-->
<xsl:when test="$foobar='foo'">
<xsl:sequence select="igs:get-my-foo-item()"/>
<xsl:when test="$css='bar'">
<xsl:sequence select="igs:get-my-bar-item()"/>

And I get such a parsing  error on my xslt :
  XTTE0570: Conditional expression: If none of the conditions is satisfied,
an empty
  sequence will be returned, but this is not allowed  [...]
Typing the parameter unfortunately won't solve this problem. The processor
isn't clever enough to work out that the implicit "otherwise" branch will
never be executed, so it will still report a type error to the effect that
the implicit "otherwise" branch returns a value (namely the empty sequence)
which doesn't conform to the required return type of the function. (There
has been some suggestion that Saxon's type checking here is too pessimistic;
the type error should be raised dynamically if this branch is taken, not
statically). The easiest way around this is probably to change the last
xsl:when condition to an xsl:otherwise.

Michael Kay

Matthieu Ricaud
Service Livre numirique

Current Thread


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.
First Name
Last Name
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.