尽管在模板中给出了后代匹配,但未捕获 [英] descendant match not caught though given in template
问题描述
我有以下 XML
<list.item><label>3.7.8</label><emphasis type="italic">健康影响</emphasis></list.item><list.item><label>3.7.8.1</label>一个健康</list.item><list.item><label><star.page>216</star.page>3.7.8.2标签>健康风险评估应包括以下关键步骤:<列表><list.item><label>(i)</label>一个系统的识别</list.item><list.item><label>(ii)</label>评估</list.item><list.item><label>(iii)</label></list.item><list.item><label>(iv)</label>推荐</list.item></list></list.item><list.item><label>3.7.8.3</label>健康</list.item><list.item><label>3.7.8.4</label>环境健康来源.</list.item><list.item><label>3.7.8.5</label>这也是必要的电子项目.(强调)</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="/"><身体><xsl:apply-templates select="root"/></html></xsl:模板><xsl:template match="root"><xsl:apply-templates select="list"/></xsl:模板><xsl:template name="orderedlist" match="list"><xsl:variable name="strl"><xsl:value-of select="descendant::list.item/label/string-length(./text())"/></xsl:变量><!--<xsl:value-of select="$strl"/>--><xsl:when test="normalize-space($strl) >'7'"><ol class="eng-orderedlistorderedlist1"><xsl:apply-templates/></ol></xsl:when><xsl:否则><ol class="eng-orderedlistorderedlist"><xsl:apply-templates/></ol></xsl:否则></xsl:选择></xsl:模板><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:when test="./text()"><xsl:apply-templates select="child::node()[not(self::label)]"/></xsl:when><xsl:否则><xsl:text> </xsl:text></xsl:否则></xsl:选择>
</xsl:模板></xsl:stylesheet>
这里我提到了 <xsl:value-of select="descendant::list.item/label/string-length(./text())"/>
并在如果它的值超过七个字符,我给出的条件应该采用 orderedlist
否则应该采用 orderedlist1
.
这里的条件是在当前列表中,如果有任何label
长度大于7(当前列表中的任何标签),则取orderedlist1
,否则 有序列表
.请让我知道我哪里出错了,我该如何解决这个问题.
谢谢
我会把你的描述在当前列表中,如果有任何长度大于 7 的标签"翻译成 <xsl:if test="descendant::list.item/label[string-length() gt 7]">...</xsl:if>
.
I've the below 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>
and the below 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>
here I've mentioned <xsl:value-of select="descendant::list.item/label/string-length(./text())"/>
and in condition i gave if its value is more than seven chars, it should take orderedlist
else should take orderedlist1
.
Here the condition is in the current list, if there are any label
whose length is greater than 7(any label in current list), it should take orderedlist1
, else orderedlist
.
please let me know where am i going wrong and how can i fix this.
Thanks
I would translate your description "in the current list, if there are any label whose length is greater than 7" into <xsl:if test="descendant::list.item/label[string-length() gt 7]">...</xsl:if>
.
这篇关于尽管在模板中给出了后代匹配,但未捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!