[Home] [By Thread] [By Date] [Recent Entries]
There seem to be two separate questions here.
I have a xsl:function which : - must return a element() - has a string param "foobar". You can declare a local type in your stylesheet: <xsl:stylesheet xmlns:fb="urn:local:foobar" ....> <xsl:import-schema> <xs:schema targetNamespace="urn:local:foobar"> <xs:simpleType name="foobarType"> <xs:restriction base="xs:string"> <xs:enumeration value="foo"/> <xs:enumeration value="bar"/> </xs:restriction> </xs:simpleType> </xs:schema> </xsl:import-schema> <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.
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 Saxonica
|

Cart



