首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检查前面的兄弟姐妹子女跟踪‘

检查前面的兄弟姐妹子女跟踪‘
EN

Stack Overflow用户
提问于 2014-06-23 12:16:27
回答 1查看 98关注 0票数 0

我有以下两个XML案例

Case1:

代码语言:javascript
复制
<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>

Case2:

代码语言:javascript
复制
<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。下面是我的XSLT。

代码语言:javascript
复制
<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>

请让我知道我哪里出了问题,以及如何解决问题。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2014-06-23 13:01:49

如果要选择以下短语的兄弟姐妹,只需使用

代码语言:javascript
复制
phrase/following-sibling::node()

当然,只有位于同一个父节点中的节点才会被选中,因为上下文节点是"para“。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24365718

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档