Altova Mailing List Archives

Re: Need some help with an expression...

From: David Allouche <david@---------------->
Date: 8/22/2000 7:36:00 PM
On Tue, 22 Aug 2000, Charles Douthart wrote:

> <box>
>    <category name="someType">
>       <header>
>         <self>
>            <host>myhost</host>
>            <instance>9</instance>
>         </self>
>        <ref>
>           <host>thathost</host>
>           <instance>1010101</instance>
>        </ref>
> </header>
> And the value of the header instance is 9 (passed from a web page to a
> servlet)
> What expression can I use to get the ref elemenent under the same header
> parent?

/box/category[@name='someType']/header is a nice start.

  Just go on you XPath until you test what you want to test:


  Now use the parent axis to go up to the header element


  Then go on as usual using the implied child axis


  It's done, but it needs to be shortened a bit to stay readable.
  First, as you know that the parent of the self element is a header
element you can use a wildcard element name without changing the meaning
of the XPath:


  Actually using parent axis with an explicit element name is only useful
to test that a parent has a given name...
  Then, if your file structure is regular enough you can put in more
wildcards without change of signification


  I guess you know enough of XSLT to use the context to get rid of any
unnecessary steps at the beginning of the XPath.

  But there is still other approaches, making heavier use of predicates,
and possibly less performant.  But it's mainly a matter of programming


//ref[ancestor::category[@name='someType'] and

Or even the most perverse and obfuscated:


(if someone can find a bug in this one I'll buy him/her a beer) :-) 

 Hope this helps. :-)

                             -- David --

 XSL-List info and archive:


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.