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

[XSLT 2.0] Determining the datatype of the value retur

Subject: [XSLT 2.0] Determining the datatype of the value returned from a function?
From: "Roger L. Costello" <costello@xxxxxxxxx>
Date: Fri, 17 Jun 2005 11:54:27 -0400
xslt determine data type
Hi Folks,
 
I am trying to create an XSLT function which returns a value that may be one
of any number of different (atomic) datatypes, e.g., xs:integer, xs:double,
xs:decimal, xs:string, etc.  With the value that the function returns I
would like to determine its datatype.  For example, if the function returns
the integer 5 then: 
 
    "$value instance of xs:integer" 
 
should yield true (assume that $value is a variable that holds the value
returned from the function).
 
Below is my attempt at solving this problem.  It does not work.  The output
that I get is: text().  Do you have a suggestion on how to solve this
problem?  (I am using SAXON 8.4) /Roger
 
<xsl:function name="ex:Test">
    <xsl:param name="letter"/>
    <xsl:choose>
         <xsl:when test="$letter eq 'A'">
             <xsl:variable name="num" select="5" as="xsd:integer"/>
             <xsl:value-of select="$num"/>
         </xsl:when>
         <xsl:when test="$letter eq 'B'">
             <xsl:variable name="num" select="5.00" as="xsd:decimal"/>
             <xsl:value-of select="$num"/>
         </xsl:when>
         ...
         <xsl:otherwise>
             <xsl:variable name="message" select="'Error'" as="xsd:string"/>
             <xsl:value-of select="$message"/>
         </xsl:otherwise>
    </xsl:choose>
</xsl:function>
 
<xsl:template match="/">
    <xsl:variable name="test1" select="'A'"/>
    <xsl:variable name="result" select="ex:Test($test1)"/>
    <xsl:choose>
        <xsl:when test="data($result) instance of xsd:integer">
            <xsl:message>INTEGER</xsl:message>
        </xsl:when>
        <xsl:when test="data($result) instance of xsd:string">
            <xsl:message>STRING</xsl:message>
        </xsl:when>
        ...
        <xsl:otherwise>
             <xsl:message>OTHER</xsl:message>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

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.