如何在不下载源代码的情况下使用EXSLT?

时间:2011-06-09 07:34:12

标签: xml xslt exslt

XSLTSL似乎声称我们可以在不下载源代码的情况下使用EXSLT:

  

直接从图书馆网站导入或包含您希望使用的主样式表或样式表模块; http://xsltsl.sourceforge.net/modules/。 modules目录始终包含最新的稳定版本。

我试过这个:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:import href="http://xsltsl.sourceforge.net/modules/string.xsl"/>
  <xsl:output method="text" indent="yes"/>

  <xsl:template match="/">
    <xsl:call-template name="str:to-upper">
      <xsl:with-param name="text">hello world</xsl:with-param>
    </xsl:call-template>
  </xsl:template>
</xsl:stylesheet>

但它不起作用。我似乎无法在不下载源代码的情况下使用EXSLT。

无论如何使用EXSLT而不下载源代码?

2 个答案:

答案 0 :(得分:1)

您没有正确使用该库。请查看说明here

下载库后,您需要:

1)向xsl文件添加导入:

<xsl:import href="string.xsl"/>

2)添加命名空间:

xmlns:str="http://xsltsl.org/string"

3)像这样调用模板:

<xsl:template match="foo">
  <xsl:call-template name="str:to-upper">
    <xsl:with-param name="text">hello world</xsl:with-param>
  </xsl:call-template>
</xsl:template>

这将产生HELLO WORLD

<强>更新

不,您不需要在本地下载库。您只需使用完整的网址链接到string.xsl

答案 1 :(得分:1)

正如Using the library中的解释一样,您需要下载它并

<xsl:import href="stdlib.xsl"/>

将其导入xslt脚本。

顺便说一句,您也可以使用xslt翻译功能:

translate(value,"abcdefghijklmnopqrstuvwxyz","ABCBCDEFGHIJKLMNOPQRSTUVWXYZ")

在多个地方使用它有点大,但只要你可以将它放在一个不重要的模板中。

相关问题