[jdom-interest] does XPath implementation work correctly?

Robert Koberg rob at koberg.com
Sun Apr 29 07:09:57 PDT 2001


It does not return what I would expect after using XPath in writing many
XSLT stylesheets.
Here are some XPath examples (xml is at the bottom of the post):
----------------------------------------------------------------------------
---------------------
Given an XPath expression of:
XPath xpath = new XPath("/");
returns...
[[Document: [DocType: <!DOCTYPE section>] Root - [Element: <section/>]]]
-- I would expect the entire document represented somehow
------------------------------------
given:
XPath xpath = new XPath("/@id");
returns...
[[Attribute: id="root"]]
-- I would expect this to return just 'root', but actually I would expect
the next expression to return the 'root' attribute value
-- there should be no value for this expression
-------------------------------------
given:
XPath xpath = new XPath("/section/@id");
returns...
[[Attribute: id="docs_000000001"], [Attribute: id="floaters_000000001"]]
-- I would expect this to return 'root'
-- it is returning the second level section 'id' attributes. In XSLT/XPath I
would have to write:
select="/section/section/@id"
-------------------------------------
given:
XPath xpath = new XPath("//*[@id='docs_000000001']");
returns...
[[Element: <section/>]]
-- I would expect this to return a representation of the child nodes of the
first child section
-------------------------------------
given:
XPath xpath = new XPath("//*[@id='docs_000000001']/@folder-name");
returns...
[[Attribute: folder-name="docs"]]
-- This seems correct but why doesn't it just return 'docs'?

=====================================================
The XML I ran the tests against:
---------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE section>
<section folder-name="" id="root" label="Blah Blah">

   <page id="index_000000000" label="Home" lang="en" name="index.html"
role="ed" type="static">
  <pointer fileref="index_en.xml" role="content" />
  <floater>
   <pointer fileref="news1.xml" role="News1" />
   <pointer fileref="news2.xml" role="News2" />
   <pointer fileref="promo1.xml" role="promo1" />
  </floater>
      <signoff>
         <user type="editor">false</user>
         <user type="qa">false</user>
      </signoff>
 </page>

 <section folder-name="docs" id="docs_000000001" label="Documentation">

      <page id="index_000000001" label="Table of Contents" lang="en"
name="index.html" role="ed" type="static">
     <pointer fileref="toc.xml" role="content" />
     <floater>
      <pointer fileref="news1.xml" role="News1" />
      <pointer fileref="news2.xml" role="News2" />
      <pointer fileref="promo1.xml" role="promo1" />
     </floater>
         <signoff>
            <user type="editor">false</user>
            <user type="qa">false</user>
         </signoff>
    </page><page>blow me!</page>
      <section folder-name="userscenario" id="userScenario_000000001"
label="User Scenario">

         <page id="us1_000000001" label="User Scenario 1" lang="en"
name="us1.html" role="doc" type="static">
        <pointer fileref="userscenario1.xml" role="content" />
        <floater>
         <pointer fileref="news1.xml" role="News1" />
         <pointer fileref="news2.xml" role="News2" />
         <pointer fileref="promo1.xml" role="promo1" />
        </floater>
            <signoff>
               <user type="editor">false</user>
               <user type="qa">false</user>
            </signoff>
       </page>

    </section>

 </section>
   <section folder-name="floaters" id="floaters_000000001"
label="_Floaters">

      <page id="floater_000000001" label="News 1" lang="en"
name="news1.html" role="ed" type="static">
     <pointer fileref="news1.xml" role="content" />
         <signoff>
            <user type="editor">false</user>
            <user type="qa">false</user>
         </signoff>
    </page>
      <page id="floater_000000002" label="News 2" lang="en"
name="news2.html" role="ed" type="static">
     <pointer fileref="news2.xml" role="content" />
         <signoff>
            <user type="editor">false</user>
            <user type="qa">false</user>
         </signoff>
    </page>
      <page id="floater_000000003" label="Promo 1" lang="en"
name="promo1.html" role="ed" type="static">
     <pointer fileref="promo1.xml" role="content" />
         <signoff>
            <user type="editor">false</user>
            <user type="qa">false</user>
         </signoff>
    </page>

   </section>

</section>






More information about the jdom-interest mailing list