首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >前一项比较中的抛出误差

前一项比较中的抛出误差
EN

Stack Overflow用户
提问于 2015-03-24 11:46:59
回答 1查看 51关注 0票数 1

我有下面的XML。

代码语言:javascript
复制
<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

代码语言:javascript
复制
 <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匹配,它给出了下面的错误。

代码语言:javascript
复制
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,以及为什么会发生此错误。

请让我知道怎样才能修好它。这是工作演示,谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-24 13:29:46

您需要使用一个变量:

代码语言:javascript
复制
   <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()的使用可能也不是您想要的,这取决于您想要比较的值。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29231874

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档