1

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">  
       &lt![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
           }        
         }
      ]]>
    &lt/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.

  • I am astonished that Chrome does not support the `object-type` EXSLT function, I thought it uses libxslt as its XSLT processor and libxslt supports that function. Maybe they disabled it in Chrome and someone should make a feature request to enable it. – Martin Honnen Aug 28 '13 at 10:43
  • Well, same here. I also found out that Chrome uses libxslt. To my knowledge libxslt does support 'object-type'. Buy it might be an old fork of the lib that Chrome is using. – user2724798 Aug 28 '13 at 13:48

1 Answers1

0

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)]"))
    
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265