匹配节点中的第一个子节点

时间:2013-12-10 10:05:56

标签: xml xslt

我有以下XML代码。

 <chapter>
  <section>
   <section level="sect2">
    <title>I<content-style format="smallcaps">ntroduction to</content-style> H<content-style format="smallcaps">ong</content-style> K<content-style format="smallcaps">ong’s</content-style> A<content-style format="smallcaps">rbitration</content-style> R<content-style format="smallcaps">egime</content-style></title>
    <figure><caption><para>Hong Kong White Book Image</para></caption><graphic href="HKWB2014_Part_U1.pdf"/></figure>
    <para id="t2_HKWB2014_Part_U1_pgfId-2"><phrase>U1/0</phrase>This section is divided into five parts:</para>
  </section>
 </section>
</chapter>

这里我需要匹配<section level="sect2">的第一个孩子。我在章节中使用了以下xslt条件。

<xsl:when test="./section/section[1]/para[1]/phrase">

上述语句与我的XML代码无关,但我想检查xml是否与下面的格式相同。

--Section
  --Section
    --para
      --phrase

该部分的第一个孩子应该是一个段落/短语,而不是标题。请告诉我如何才能与之匹敌。

由于

1 个答案:

答案 0 :(得分:1)

使用<xsl:when test="section/section[1]/*[1][self::para[phrase]]">

相关问题