Xslt 比较前一个元素时抛出错误
我有下面的XMLXslt 比较前一个元素时抛出错误,xslt,xslt-2.0,Xslt,Xslt 2.0,我有下面的XML <body> <para> <phrase>[1.001]</phrase> Arrest is for the pu</para> <para> <phrase>[1.002]</phrase> Brandon J said in </para> <para> <phrase>[1
<body>
<para>
<phrase>[1.001]</phrase> Arrest is for the pu</para>
<para>
<phrase>[1.002]</phrase> Brandon J said in
</para>
<para>
<phrase>[1.001]</phrase> Singapore used to be and is still
</para>
</body>
在这里,我无法理解什么是XPTY:0020
,以及为什么会发生此错误
请让我知道如何修理它。
这是你的电话号码
谢谢您需要使用一个变量:
<xsl:template name="phrase" match="phrase">
<xsl:variable name="this-phrase" select="."/>
<span class="phrase">
<xsl:analyze-string select="." regex="\[([0-9]+)\.([0-9]+)\]">
<xsl:matching-substring>
<xsl:choose>
<xsl:when test="$this-phrase/preceding::phrase[contains(., current())]">
显然,
current()
的使用也可能不是您想要的,这取决于您想要比较的值 您无法测试前面的节点,因为您位于匹配的子字符串(xs:string)下。首先修改代码以执行测试,然后再对字符串进行分析。它不起作用的原因是在xsl:analyze string
内上下文节点已更改为原子类型(xs:string
),并且您在xs:string
项上使用了前面的轴,这肯定是错误的。要更正它,可以在xsl:analyze string
之前使用一个变量(或序列),并将previous::phrase
的值存储在其中,然后在xsl:analyze string
中使用变量,而不是使用前面的轴。
Error on line 41
XPTY0020: Required item type of the context item for the preceding axis is node();
supplied value has item type xs:string
<xsl:template name="phrase" match="phrase">
<xsl:variable name="this-phrase" select="."/>
<span class="phrase">
<xsl:analyze-string select="." regex="\[([0-9]+)\.([0-9]+)\]">
<xsl:matching-substring>
<xsl:choose>
<xsl:when test="$this-phrase/preceding::phrase[contains(., current())]">