[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: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Wed, 2 Feb 2011 21:13:28 +0530
Re:  strong typed variable with restriction ?
Hi Matthieu,
    I would question the use of function for this need. Since the
input parameter has only 2 states ('foo' and 'bar'), perhaps an XSLT
code fragment as follows should be sufficient (i.e this looks like a
simple if-then-else kind of abstraction).

    <xsl:when test="$foobar='foo'">
        <xsl:copy-of select="igs:get-my-foo-item()" />
    <xsl:when test="$foobar='bar'">
        <xsl:copy-of select="igs:get-my-bar-item()" />

I believe functions should normally be designed when input parameters
have potentially numerous states (of-course there may be exceptions to
this observation, but this appears to be commonsense module/function
design principle to me).

On Wed, Feb 2, 2011 at 3:46 PM, Matthieu Ricaud-Dussarget
<matthieu.ricaud@xxxxxxxxx> wrote:
> Hi all,
> 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
> "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 ?
> 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:choose>
> <xsl:when test="$foobar='foo'">
> <xsl:sequence select="igs:get-my-foo-item()"/>
> </xsl:when>
> <xsl:when test="$css='bar'">
> <xsl:sequence select="igs:get-my-bar-item()"/>
> </xsl:when>
> </xsl:choose>
> </xsl:function>
> And I get such a parsing B error on my xslt :
> B XTTE0570: Conditional expression: If none of the conditions is satisfied,
> an empty
> B sequence will be returned, but this is not allowed B [...]
> Should I import my own schema to my xsl to define my special type derived
> from xs:string ?
> Thanks for your advices,
> Matthieu.
> --
> Matthieu Ricaud
> Service Livre numC)rique

Mukul Gandhi

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.