标签: functx

在 XSLT 中使用函数

我正在学习 XSLT。这些问题可能很明显,但我现在真的被困住了。Oxygen 返回以下两种错误:

  1. 未为“ownFunction()”声明命名空间。(“未声明的命名空间前缀 {xs}”)

  2. 未知系统函数 index-of-string()
    index-of-string我从这个网站得到的 XSLT 函数似乎无法识别

这是 XSL 文件的简化版本:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"     xmlns:foo="http://www.wathever.com">
<xsl:output method="xml" />

  <xsl:function name="foo:ownFunction" as="xs:string">
    <xsl:param name="string" as="xs:string"/>

        <xsl:choose>

          <xsl:when test='contains($string,"src=")'>
            <xsl:variable name="position"><xsl:value-of select="index-of-string($string,'src=')"/>+<xsl:number value="10"/></xsl:variable>
            <xsl:variable name="partString"><xsl:value-of select="substring($string,$position)"/></xsl:variable>
            <xsl:variable name="length"><xsl:value-of select="index-of-string($partString,'quot;')"/> - <xsl:number value="2"/></xsl:variable>
            <xsl:value-of select="substring($partString,1,$length)"/>
          </xsl:when>

          <xsl:otherwise>
            <xsl:value-of select="hotpot-jmatch-file/data/title"/>
          </xsl:otherwise>

        </xsl:choose>
  </xsl:function>

  <xsl:template match="/">
    <data>
      <title>
        <xsl:variable name="string"><xsl:value-of select="hotpot-jmatch-file/data/title"/></xsl:variable>
        <xsl:value-of select="foo:ownFunction($string)"/>
      </title>
    </data>
  </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

xslt xpath functx

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

functx ×1

xpath ×1

xslt ×1