detect availability of node-set() function in xslt implementation of icecast server

拈花ヽ惹草 提交于 2019-12-09 20:08:46

问题


Icecast contains an XSLT implementation based on libxslt from xmlsoft.

I want to know if it supports the node-set() function, preferably in a way that works for other web-only environments too:

Regrettably, the XSLT processor in icecast is only web accessible through the web interface of the icecast process (so no xsltproc on the commandline). To worsen it: there is limited logging of the XSLT errors (when you do things wrong, the icecast process often just dies).

I'm running icecast 2.3.2 as that is the latest Windows based build (there is no 2.3.3 build for Windows yet), which has libxslt.dll dated in 2008. There is no version number in the DLL, the best I can provide is this (see XSLT code at the bottom):

Version:    1.0
Vendor:     libxslt
Vendor URL: http://xmlsoft.org/XSLT/

I tried running the node-set detection mentioned at David Carlisle's blog article The EXSLT node-set function pointed to by "How to use node-set function in a platform-independent way?".

From the output, I think that fails:

icemaster@localhost972990localhost00EarthIcecast 2.3.2Sun, 23 Jun 2013 20:02:19 W. Europe Daylight Time202200ice-samplerate=44100;ice-bitrate=64;ice-channels=264StationGenre6424410000http://localhost:8000.....

What would be the best way to find out through an XSL file in the web-interface?

Version script:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  <xsl:output method="text" encoding="UTF-8" />
  <xsl:template match="/">
Version:    <xsl:value-of select="system-property('xsl:version')" />
Vendor:     <xsl:value-of select="system-property('xsl:vendor')" />
Vendor URL: <xsl:value-of select="system-property('xsl:vendor-url')" />
  </xsl:template>
</xsl:stylesheet>

node-set script I tried:

<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exslt="http://exslt.org/common"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  exclude-result-prefixes="exslt msxsl">

<xsl:output
  omit-xml-declaration="no"
  method="html"
  indent="yes"
  encoding="UTF-8" />

<msxsl:script language="JScript" implements-prefix="exslt">
 this['node-set'] =  function (x) {
  return x;
  }
</msxsl:script>

<xsl:variable name="x">
  <y/>
</xsl:variable>

<xsl:template match="x">
  <html>
    <head><title>test exslt node set</title></head>
    <body>
      <xsl:apply-templates select="exslt:node-set($x)/*"/>
    </body>
  </html>
</xsl:template>

<xsl:template match="y">
  <p>node set!</p>
</xsl:template>

</xsl:stylesheet>

回答1:


Short answer

libxslt in icecast supports the xt:node-set() function.
Underneath it is implemented in by the xsltFunctionNodeSet() function.

Generic answer

I created a solution, based on the CSTUG bibliography XSLT using the function system-property.

Please comment if this is indeed the correct way to do this.

The CSTUG code handles these node-set() functions:

  • exslt:node-set()
  • msxml:node-set()
  • xalanc:nodeset()

I added support for these as well:

  • xt:node-set()
  • saxon6:node-set()

Output from icecast:

Version:    1.0
Vendor:     libxslt
Vendor URL: http://xmlsoft.org/XSLT/
node-set(): xt:node-set()

XSLT used:

<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exslt="http://exslt.org/common"
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:xalanc="http://xml.apache.org/xalanc"
  xmlns:xt="http://www.jclark.com/xt"
  xmlns:saxon6="http://icl.com/saxon"
  extension-element-prefixes="exslt msxml xalanc xt saxon6"
  exclude-result-prefixes="exslt msxml xalanc xt saxon6"
  >

  <xsl:output method="text" encoding="UTF-8" />
  <xsl:template match="/">
    <xsl:text>
Version:    </xsl:text>
    <xsl:value-of select="system-property('xsl:version')" />
    <xsl:text>
Vendor:     </xsl:text>
    <xsl:value-of select="system-property('xsl:vendor')" />
    <xsl:text>
Vendor URL: </xsl:text>
    <xsl:value-of select="system-property('xsl:vendor-url')" />
<!--
Prefixes used for node-set()
exslt: EXSLT aware processors (Saxon, xsltproc, Xalan-J, jd.xslt, 4XSLT)
msxml: MSXML
xalanc: Xalan-C, Xalan-J 2.6.x
xt: XT, libxslt
saxon6: Saxon 6
-->
    <xsl:text>
node-set(): </xsl:text>
    <xsl:choose>
      <xsl:when test="function-available('exslt:node-set')">
        <xsl:text>exslt:node-set()</xsl:text>
      </xsl:when>
      <xsl:when test="function-available('msxml:node-set')">
        <xsl:text>msxml:node-set()</xsl:text>
      </xsl:when>
      <xsl:when test="function-available('xalanc:nodeset')">
        <xsl:text>xalanc:nodeset()</xsl:text>
      </xsl:when>
      <xsl:when test="function-available('xt:node-set')">
        <xsl:text>xt:node-set()</xsl:text>
      </xsl:when>
      <xsl:when test="function-available('saxon6:node-set')">
        <xsl:text>saxon6:node-set()</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>EXSLT:node-set not found!</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>


来源:https://stackoverflow.com/questions/17265064/detect-availability-of-node-set-function-in-xslt-implementation-of-icecast-ser

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!