我使用tokenize()函数来迭代一组值,但是我尝试在模板调用中使用这些值--出现"Not a node item“错误。
<xsl:for-each select="tokenize($edge_pairs,';')">
<xsl:if test="number(string-length(.)) > 0">
<xsl:variable name="c_row" select="." as="xs:string"/>
<xsl:variable name="src" select="substring-before($c_row,':')" as="xs:string"/>
<xsl:variable name="dst" select="substring-after($c_row,':')" as="xs:string"/>
<xsl:call-template name="links">
<xsl:with-param name="src1" select="$src"/>
<xsl:with-param name="dst1" select="$dst"/>
</xsl:call-template>
</xsl:if>
</xsl:for-each>这是触发错误的原始数据:
<xsl:for-each select="root()//gml:edge[@source = $src1 and @target = $dst1 or @source = $dst1 and @target = $src1]">发布于 2014-11-23 07:04:36
假设触发错误的代码在命名模板links中,那么问题是您不再处于源XML文档的上下文中。您在一个标记化字符串上的xsl:for-each中,所以上下文是一个原子值(即单个字符串)。
<xsl:for-each select="tokenize(a,';')">这意味着root()函数将不起作用,因为上下文是一个字符串,而不是document对象中的节点。
解决方案是定义一个全局变量(即xsl:stylesheet的子变量,在任何模板之外),它引用根:
<xsl:variable name="root" select="root()" />然后,您可以将失败的xsl:for-each更改为:
<xsl:for-each select="$root//gml:edge[(@source = $src1 and @target = $dst1) or (@source = $dst1 and @target = $src1)]">https://stackoverflow.com/questions/27082314
复制相似问题