Wednesday, 4 March 2015

Xpath: If inside a node, test to see if it is located inside a certain attribute and if there is another similar node



I have this xml file



<book>
<chapter category="AIRCRAFT">
<title>Flight Controls</title>
<section>Bombardier</title>
<orderedlist>
<listitem><para>list item 1</para></listitem>
<listitem><para>list item 2</para></listitem>
<listitem><para>list item 3</para></listitem>
</orderedlist>
</section>
</chapter>

<chapter category="PILOT">
<title>Flight Operations</title>
<section>
<title>Crew Bases</title>
<orderedlist>
<listitem><para>list item 1</para></listitem>
<listitem><para>list item 2
<note>
<para>Note: Additional information.</para>
</note>
</para>
</listitem>
<listitem><para>list item 3</para></listitem>
</orderedlist>
</section>
</chapter>

<chapter category="MAINTENANCE">
<title>Maintenance</title>
<section>
<title>Maintenance Bases</title>
<orderedlist>
<listitem><para>list item 1</para></listitem>
<listitem><para>list item 2</para></listitem>
<listitem><para>list item 3</para></listitem>
</orderedlist>
</section>
</chapter>

<chapter category="COMPANY">
<title>Company Policy Manual</title>
<section>
<title>Employment Standards and Eligibility</title>
<orderedlist>
<listitem><para>list item 1</para></listitem>
<listitem><para>list item 2</para></listitem>
<listitem><para>list item 3</para></listitem>
</orderedlist>
</section>
</chapter>

</book>


I need to answer these two questions:


1)If inside a para element, test to see if it is located inside the chapter with the category attribute set to “MAINTENANCE”


2)If inside a listitem element, test to see if there is another listitem before it


I need just the statements.


No comments:

Post a Comment