Xslt 2.0 虽然在模板中给出,但未捕获子体匹配
我有下面的XMLXslt 2.0 虽然在模板中给出,但未捕获子体匹配,xslt-2.0,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>
<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>
3.7.8健康影响
3.7.8.1健康
216 3.7.8.2健康风险评估应包括以下关键步骤:
(i) 系统鉴定
(ii)评估
(iii)一项
(四)建议
3.7.8.3健康
3.7.8.4环境卫生源。
3.7.8.5这也是e项目所必需的。(重点已提供)
下面是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> </xsl:text>
</xsl:otherwise>
</xsl:choose>
</div>
</li>
</xsl:template>
</xsl:stylesheet>
这里我提到了
,在我给出的条件中,如果它的值大于7个字符,它应该取orderedlist
,否则应该取orderedlist1
此处条件在当前列表中,如果有长度大于7的标签
(当前列表中的任何标签),则应采用orderedlist1
,否则orderedlist
。
请让我知道我哪里出了问题,我怎样才能解决这个问题
谢谢如果有长度大于7”的标签,我会将当前列表中的“描述”翻译成
…
嗨,Martin,感谢您的快速响应,这很好,但是当出现类似94(a)
的情况时,orderedlist1
被捕获,而不是orderedlist
那么您的英文描述“长度更大的标签”将包括标签内的文本,包括其他子元素或子元素的文本,这就是为什么我选择了标签[string-length()gt 7]
。如果您不想这样做,那么我们需要更好地描述您想要的长度,可能是genderant::list.item/label[string length(string join(text(),“”))gt 7]
,它将连接所有文本节点子节点,然后计算长度。这是否排除了任何其他子节点。我只考虑文本?是的,text()
是child::text()
的缩写,并选择所有子文本节点,字符串连接将值连接起来。我想忽略子节点(star.text
):-(