XSLT function exslt:object-type in IE and Chrome

588 views Asked by At

EXSLT provides a set of useful extensions to XSLT. Probably most of us have used exslt:node-set function. One of the other function specified by EXSLT is 'exslt:object-type'. Unfortunately, most browsers (except Firefox) seem not to support this function. Ref: http://greenbytes.de/tech/tc/xslt/ While I managed to implement this function in IE using script, I do not seem to find a workaround for Google Chrome. (This is one of the times that IE seems to be superior to Chrome).

The main objective in my application is to find out if the argument is a 'node-set' or not. Or to be more precise - if the argument can be selected in xsl:apply-templates.

The IE implementation can look similar to this one:


    <msxso:script language="JScript" implements-prefix="exslt">  
       <![CDATA[
         this['object-type'] = function(x) {
           switch (typeof x) {
            case "number": return "number";
            case "string": return "string";
            case "object": return "node-set";
            default: return typeof x
           }        
         }
      ]]>
    </msxso:script>   

So the question is - how to do something similar in Google Chrome.

Please understand that the solution is not to manually rewrite the source stylesheet as this is supposed to be fully automotised process.

My scenario is following: agent submits XML + XSLT, the process automatically rewrites XSLT to convert xsl:value-of into xsl:apply-templates. While the type of the select attribute of xsl:value-of does not matter, xsl:apply-templates will fail when the select attribute cannot be resolved to a node-set.

1

There are 1 answers

1
Paul Sweatte On

Use a combination of libraries to do type checking:

  • XSLTSL: node:type

    <xsl:template name="node:type"><xsl:param name="node" select="."/>  ...</xsl:template>
    
  • XSieve: x:string

    (x:string (x:eval "/data//text()[not(ancestor-or-self::bad)]"))