我有下面的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.001]</phrase> Singapore used to be and is still
</para>
</body>和下面的XSLT
<xsl:template name="para" match="para">
<xsl:apply-templates select="./node()[1][self::page]" mode="first"/>
<div>
<xsl:choose>
<xsl:when test="./@align">
<xsl:attribute name="class"><xsl:text>para align-</xsl:text><xsl:value-of select="./@align"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="class"><xsl:text>para</xsl:text></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template name="phrase" match="phrase">
<span class="phrase">
<xsl:analyze-string select="." regex="\[([0-9]+)\.([0-9]+)\]">
<xsl:matching-substring>
<xsl:choose>
<xsl:when test="preceding::phrase[contains(., current())]">
<a name="{concat('CP',format-number(number(regex-group(1)),'0'),'-',format-number(number(regex-group(2)),'000'))}">
<xsl:value-of select="."/>
</a>
</xsl:when>
<xsl:otherwise>
<a name="{concat('P',format-number(number(regex-group(1)),'0'),'-',format-number(number(regex-group(2)),'000'))}">
<xsl:value-of select="."/>
</a>
</xsl:otherwise>
</xsl:choose>
<a name="{concat('P',format-number(number(regex-group(1)),'0'),'-',format-number(number(regex-group(2)),'000'))}">
</a>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</span>
</xsl:template>在这里,我试图将phrase与任何一个preceding phrase匹配,它给出了下面的错误。
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在这里,我无法理解什么是XPTY:0020,以及为什么会发生此错误。
请让我知道怎样才能修好它。这是工作演示,谢谢
发布于 2015-03-24 13:29:46
您需要使用一个变量:
<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()的使用可能也不是您想要的,这取决于您想要比较的值。
https://stackoverflow.com/questions/29231874
复制相似问题