问题
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
回答1:
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>.
来源:https://stackoverflow.com/questions/27122648/descendant-match-not-caught-though-given-in-template