2

特定のノードの前にすべてのノードを一致させようとしています。入力XML

<story>
  <content>
    <p>This is the text I want</p>
    <p>This is the text I want</p>
    <p>This is the text I want</p>
    <ul>
       <li></li>
       ...
    </ul>
    ....
    ....
  </content>
</story>

<p>それを入力XMLとして使用して、タグの前にあるすべてのタグを取得し<ul>てレンダリングしようとしていますが、失敗しています。<p>タグが0個または無限である可能性があります。XSLT 1.0でこれを行う方法について何か考えはありますか?ありがとう!

4

2 に答える 2

2
/story/content/p[not(preceding-sibling::ul)]
于 2012-12-13T19:47:34.953 に答える
0

使用

//p[not(preceding::ul or ancestor::ul)]

これは一般的に間違っています:

//p[not(preceding-sibling::ul)]

pの前にある要素は選択ulされませんが、の兄弟ではないためulです。

たとえば、次のXMLドキュメントがあるとします

<story>
  <div>
    <p>Must be selected</p>
  </div>
  <ul>
    <li><p>Must not be selected</p></li>
  </ul>
  <content>
    <p>Must not be selected</p>
    <div>
      <p>Must not be selected</p>
    </div>
    <p>Must not be selected</p>
    <p>Must not be selected</p>
    <ul>
       <li></li>
       <li><p>This must not be selected</p></li>
    </ul>
    ....
    ....
  </content>
</story>

上記の間違った式は以下を選択します

<p>Must not be selected</p>
<p>Must not be selected</p>
<p>Must not be selected</p>

必要な要素を選択しません:

<p>Must be selected</p>

しかし、この回答の最初の正しい式は、必要なp要素だけを選択します。

<p>Must be selected</p>
于 2012-12-14T01:24:05.190 に答える