previous  next

typeswitch

typeswitch is often cited as a feature of XQuery not in XSLT, which is true, but it maps fairly easily to an xsl:choose construct.

typeswitch (2)
  case $zip as element(*)
       return 7
  default $x return 9
  <xsl:variable as="item()*" name="xq:ts" select="( 2 ,())"/>
  <xsl:choose>
    <xsl:when test="$xq:ts instance of  element(  * )">
        <xsl:variable as=" element(  * )" name="zip" select="$xq:ts"/>
        <xsl:sequence select=" 7 "/>
     </xsl:when>
     <xsl:otherwise>
        <xsl:variable as="item()*" name="x" select="$xq:ts"/>
        <xsl:sequence select=" 9 "/>
     </xsl:otherwise>
  </xsl:choose>