我是以下的XML。
<orderedlist type="manual">
<item num="1."><para>identify the issues in dispute;</para></item>
<item num="1.1"><para>explore and generate options;</para></item>
<item num="1.1.1"><para>communicate with one another; and/or</para></item>
<item num="(i)"><para>copy of the cancellation of employment pass; and</para></item>
<orderedlist>
在这里,我想将.
中的所有-
翻译为item-num
并用不同的标记将其包围,其中.
之后有一些数字或句点#39;我收到了解决方案并且我已经使用了not(ends-with(./@num,'.'))
。这一点工作正常,直到某些时候,最近我遇到了一种情况(上述XML中的第4 item num
条)item num
中有(i), i, a, a)
之类的值,这些也满足条件正在获得新的tag
。下面是我的XSL模板。
<xsl:template name="orderedlist" match="orderedlist">
<ol class="eng-orderedlist orderedlist">
<xsl:apply-templates/>
</ol>
</xsl:template>
<xsl:template match="item">
<xsl:call-template name="paran"></xsl:call-template>
</xsl:template>
<xsl:template name="paran">
<xsl:apply-templates select="./para/node()[1][self::page]" mode="first"/>
<li class="item">
<div class="para">
<xsl:choose>
<xsl:when test="not(ends-with(./@num,'.'))">
<a name="{translate(./@num,'.','-')}"/>
<span class="phrase">
<xsl:value-of select="./@num"></xsl:value-of>
</span>
</xsl:when>
<xsl:when test="./@num">
<span class="item-num">
<xsl:value-of select="./@num"></xsl:value-of>
</span>
</xsl:when>
</xsl:choose>
<xsl:apply-templates/>
</div>
</li>
</xsl:template>
<xsl:template match="page[not(preceding-sibling::node()[not(self::text()) or normalize-space()])]"/>
此处我不希望phrase
围绕其他数字而不是格式X.X
X.X.X
。
您可以找到此问题的演示here。
请让我知道如何解决它。
由于
答案 0 :(得分:2)
我建议你这样做:
<xsl:template match="item">
<!-- do one thing here -->
</xsl:template>
<xsl:template match="item [not(ends-with(@num, '.'))] [not (translate(@num, '.123456789', ''))]">
<!-- do another thing here -->
</xsl:template>
-
按照伊恩·罗伯茨的建议,用正则表达式做谓词可能会更优雅。
答案 1 :(得分:2)
也许你需要先检查一下 num 属性是否包含一个句号
<xsl:when test="contains(@num, '.') and not(ends-with(./@num,'.'))">
即。 @num 包含一个句号,但最后不是一个。