虽然在模板中给出了后代匹配但未被捕获

时间:2014-11-25 09:13:57

标签: xslt-2.0

我有以下XML

<list>
     <list.item><label>3.7.8</label>    <emphasis type="italic">Health Impact</emphasis></list.item>
    <list.item><label>3.7.8.1</label>   A health </list.item>
    <list.item><label><star.page>216</star.page> 3.7.8.2</label>    The health risk assessment shall include the following key steps:
      <list>
        <list.item><label>(i)</label>   a systematic identification</list.item>
        <list.item><label>(ii)</label>  an assessment</list.item>
        <list.item><label>(iii)</label> an </list.item>
        <list.item><label>(iv)</label>  recommendation </list.item>
     </list>
    </list.item>
    <list.item><label>3.7.8.3</label>   The health </list.item>
    <list.item><label>3.7.8.4</label>   The environmental health sources.</list.item>
    <list.item><label>3.7.8.5</label>   It is also necessary e Project. (emphasis supplied)</list.item>
</list>

以及下面的XSL

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
    <xsl:output method="html"/>
    <xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="root"/>
</body>
</html>

    </xsl:template>
<xsl:template match="root">
<xsl:apply-templates select="list"/>
</xsl:template>

<xsl:template name="orderedlist" match="list">
<xsl:variable name="strl">
<xsl:value-of select="descendant::list.item/label/string-length(./text())"/>
</xsl:variable>
<!--<xsl:value-of select="$strl"/>-->
    <xsl:choose>
        <xsl:when test="normalize-space($strl) > '7'">
            <ol class="eng-orderedlist orderedlist1">
            <xsl:apply-templates/>
        </ol>
        </xsl:when>
        <xsl:otherwise>
            <ol class="eng-orderedlist orderedlist">
            <xsl:apply-templates/>
        </ol>
        </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    <xsl:template name="orderitem" match="list.item">
        <xsl:apply-templates select="./label/node()[1][self::star.page]" mode="first"/>
        <li class="item">
            <div class="para">
                <xsl:if test="./label">
                    <span class="item-num">
                        <xsl:value-of select="./label/text()"/>
                    </span>
                </xsl:if>
                <xsl:choose>
                    <xsl:when test="./text()">
                        <xsl:apply-templates select="child::node()[not(self::label)]"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text>&#160;</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
            </div>
        </li>
    </xsl:template>
</xsl:stylesheet>

这里我提到了<xsl:value-of select="descendant::list.item/label/string-length(./text())"/>,如果我的价值超过7个字符,我应该orderedlist其他人应该orderedlist1

此处条件位于当前列表中,如果有任何label长度大于7(当前列表中的任何标签),则应采用orderedlist1,否则orderedlist 。  请让我知道我哪里出错了,我该怎么办呢。

由于

1 个答案:

答案 0 :(得分:1)

我会将您的描述“在当前列表中,如果有任何长度大于7的标签”翻译成<xsl:if test="descendant::list.item/label[string-length() gt 7]">...</xsl:if>