title: Match node except for grandchild node
body: <h1>Background</h1>
  
  <p>Converting a document from OpenOffice to DocBook format.</p>
  
  <h1>Problem</h1>
  
  <p>Parts of the document include the following:</p>
  
  <pre><code>&lt;ul&gt;&lt;li&gt;&lt;ul&gt;&lt;li&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;...&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
  </code></pre>
  
  <p>While other parts of the document include:</p>
  
  <pre><code>&lt;ul&gt;&lt;li&gt;&lt;p&gt;...&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
  </code></pre>
  
  <p>I tried to match just the inner-most <code>ul</code> tag using:</p>
  
  <pre><code>&lt;xsl:template match="xhtml:ul[not(child::xhtml:li/child::xhtml:ul)]"&gt;
  ...
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>But this does not match. The following expression:</p>
  
  <pre><code>&lt;xsl:template match="xhtml:ul"&gt;
  </code></pre>
  
  <p>Will create, as expected:</p>
  
  <pre><code>&lt;itemizedlist&gt;
  &lt;itemizedlist&gt;
  &lt;itemizedlist&gt;
  ...
  &lt;/itemizedlist&gt;
  &lt;/itemizedlist&gt;
  &lt;/itemizedlist&gt;
  </code></pre>
  
  <h3>Desired Output</h3>
  
  <p>The desired output format, regardless of <code>ul</code> nesting, is:</p>
  
  <pre><code>&lt;itemizedlist&gt;
  ...
  &lt;/itemizedlist&gt;
  </code></pre>
  
  <h1>Question</h1>
  
  <p>What's the correct syntax for matching the innermost child <code>ul</code> node?</p>
  
  <h1>Ideas</h1>
  
  <p>There are a few ways to resolve this:</p>
  
  <ul>
  <li>Search/replace the original document (there are only ~20 instances).</li>
  <li>Use <code>xsl:test</code> within the <code>li</code> node to see if the child node is <code>ul</code>.</li>
  </ul>
  
  <p>What XPath expression would work? For example:</p>
  
  <pre><code>&lt;xsl:template match="xhtml:ul[not(grandchild::xhtml:ul)]"&gt;
  </code></pre>
  
  <p>Thank you!</p>