Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get the most deeply nested element nodes using xpath? (implementation with XMLTWIG)
    primarykey
    data
    text
    <p>I need to extract (XSLT, xpath, xquery... Preferably xpath) the <strong>most deeply nested element</strong> nodes with <strong>method</strong> (DEST id="RUSSIA" method="delete"/>) and his direct ancestor (SOURCE id="AFRICA" method="modify">).</p> <p>I don't want to get the top nodes with methods ( main method="modify"> or main method="modify"> ).</p> <p>The deepest nested elements with method correspond to real actions. The top elements with method actually are dummy actions that must not be taken into account.</p> <p>Here is my XML sample file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;main method="modify"&gt; &lt;MACHINE method="modify"&gt; &lt;SOURCE id="AFRICA" method="modify"&gt; &lt;DEST id="RUSSIA" method="delete"/&gt; &lt;DEST id="USA" method="modify"/&gt; &lt;/SOURCE&gt; &lt;SOURCE id="USA" method="modify"&gt; &lt;DEST id="AUSTRALIA" method="modify"/&gt; &lt;DEST id="CANADA" method="create"/&gt; &lt;/SOURCE&gt; &lt;/MACHINE&gt; &lt;/main&gt; </code></pre> <p>This is Xpath output I expect:</p> <pre><code>&lt;SOURCE id="AFRICA" method="modify"&gt;&lt;DEST id="RUSSIA" method="delete"/&gt; &lt;SOURCE id="AFRICA" method="modify"&gt;&lt;DEST id="USA" method="modify"/&gt; &lt;SOURCE id="USA" method="modify"&gt;&lt;DEST id="AUSTRALIA" method="modify"/&gt; &lt;SOURCE id="USA" method="modify"&gt;&lt;DEST id="CANADA" method="create"/&gt; </code></pre> <p>My current xpath command does not provide the adequate result.</p> <p>Command xpath("//[@method]/ancestor::*") which is returning:</p> <pre><code>&lt;main&gt;&lt;MACHINE method="modify"&gt; # NOT WANTED &lt;MACHINE method="modify"&gt;&lt;SOURCE id="AFRICA" method="modify"&gt; # NOT WANTED &lt;MACHINE method="modify"&gt;&lt;SOURCE id="USA" method="modify"&gt; # NOT WANTED &lt;SOURCE id="AFRICA" method="modify"&gt;&lt;DEST id="RUSSIA" method="delete"/&gt; &lt;SOURCE id="AFRICA" method="modify"&gt;&lt;DEST id="USA" method="modify"/&gt; &lt;SOURCE id="USA" method="modify"&gt;&lt;DEST id="AUSTRALIA" method="modify"/&gt; &lt;SOURCE id="USA" method="modify"&gt;&lt;DEST id="CANADA" method="create"/&gt; </code></pre> <p>My xmltwig code for additional information (context):</p> <pre><code>#!/usr/bin/perl -w use warnings; use XML::Twig; use XML::XPath; @my $t= XML::Twig-&gt;new; my $v= XML::Twig::Elt-&gt;new; $t-&gt; parsefile ('input.xml'); @abc=$t-&gt;get_xpath("\/\/[\@method]\/ancestor\:\:\*") ; foreach $v (@abc) # outer 1 { foreach $v ($v -&gt;children) # internal 1 { $w=$v-&gt;parent; print $w-&gt;start_tag; print $v-&gt;start_tag; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload