xsl-list
[Top] [All Lists]

Re: [xsl] strong typed variable with restriction ?

2011-02-02 10:00:09
Hi Mukul,

The code I sent was actually simple, a kind of "school case" so you're right to notice this. But in my real case there are 4 parameters for this function, and only two of them need to be so restricted, not the others.

I sent a mail on this topic with my real code which is quite different.
In this code there is a mistake that I just have seen : a param and a variable has the same name ($css), which was not an error for the processor but was one from the coding point of view.

Regards,
Matthieu.

Le 02/02/2011 16:43, Mukul Gandhi a écrit :
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:choose>
     <xsl:when test="$foobar='foo'">
         <xsl:copy-of select="igs:get-my-foo-item()" />
     </xsl:when>
     <xsl:when test="$foobar='bar'">
         <xsl:copy-of select="igs:get-my-bar-item()" />
     </xsl:when>
</xsl:choose>

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(_dot_)ricaud(_at_)igs-cp(_dot_)fr>  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 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 ?

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

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
IGS-CP
Service Livre numérique




--
Matthieu Ricaud
IGS-CP
Service Livre numérique



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

<Prev in Thread] Current Thread [Next in Thread>