检查前面的兄弟孩子followingsiblings`

时间:2014-06-23 12:16:28

标签: xslt

我有以下2个XML案例

情况1:

<para>
<phrase>21.001</phrase>
 <content-style font-style="italic">Modern wordings.</content-style> The modern 
      form of the hulls clauses goes back to 1982 and those clauses remain in 
      widespread use. The Hulls clauses were revised in a number of significant
</para>

情况2:

<para>
  <phrase>21.146</phrase>
</para>
<para>
   <content-style font-style="bold">14.</content-style> Where the ship has stranded,
     the insurer is liable for the excepted losses, although the loss is not       
     attributable to the stranding, provided that when the stranding takes place the 
     risk has attached and if the policy be on goods, that the damaged goods are 
     on board.
</para>

这里我试图检查是否有following-sibling to phrase, which is child of para,但这两种情况的条件都是true,其中条件只应为 Case1 < / strong>即可。下面是我的XSLT。

<xsl:template name="para" match="para">
    <xsl:if test="not(preceding-sibling::para/phrase/following-sibling::node())">
    <div>
<xsl:choose>
    <xsl:when test="./@align">
<xsl:attribute name="class">
                            <xsl:text>para align-</xsl:text>
                            <xsl:value-of select="./@align"/>
                        </xsl:attribute>    
                        </xsl:when>
                        <xsl:otherwise>
                        <xsl:attribute name="class">
                            <xsl:text>para</xsl:text>
                        </xsl:attribute>    
                        </xsl:otherwise>
</xsl:choose>
<xsl:apply-templates/>
 </div>    
    </xsl:if>
     </xsl:template>

请让我知道我哪里出错了,我该怎么办呢。

由于

1 个答案:

答案 0 :(得分:0)

如果您想选择以下兄弟的短语,请使用

phrase/following-sibling::node()

当然,只会选择同一父节点中的节点,因为您的上下文节点是“para”