我正在学习 XSLT。这些问题可能很明显,但我现在真的被困住了。Oxygen 返回以下两种错误:
未为“ownFunction()”声明命名空间。(“未声明的命名空间前缀 {xs}”)
未知系统函数 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)
Oxygen 返回以下两种错误:
1) 未为“ownFunction()”声明命名空间。(“未声明的命名空间前缀 {xs}”)
这实际上是一个 XML 问题。任何 XSLT 样式表都不可能是格式良好的 XML 文档。在对格式良好的其他要求中,使用的任何命名空间前缀都必须绑定到命名空间声明中的命名空间 URI。
要更正此绑定"xs"前缀"http://www.w3.org/2001/XMLSchema"- 这意味着添加xmlns:xs="http://www.w3.org/2001/XMLSchema"到元素(通常顶部元素是此命名空间的不错选择。
你有同样的问题"foo:ownFunction"。"foo"在使用它之前,您必须绑定/定义和可见前缀。只需添加xmlns:foo="my:foo"到样式表的顶部元素即可。
2) “未知的系统函数 index-of-string()”。我从这个网站得到的 XSLT 函数“index-of-string”似乎没有被识别:http : //www.xsltfunctions.com/xsl/functx_index-of-string.html
您忘记了从 Priscilla Walmsley 的站点复制并粘贴该函数,或者将其保存在单独的文件中(推荐),然后使用<xsl:import>或<xsl:include>将此样式表文件导入/包含到您的转换中。
最后,此类问题表明您需要更系统地介绍 XSLT。买一本好书,好好读一读。你不会后悔的。这个答案可能有助于列出我认为好的 XSLT 和 XPath 学习资源。
| 归档时间: |
|
| 查看次数: |
16805 次 |
| 最近记录: |