This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Selecting specific ancestory by relation and name


I want to get the value of a certain sibling of the current element, but
only if the current element's parent is of a certain type.  In other words,
suppose I'm creating the template for B elements.  My input XML may look
like (these are just fragments):

<A>
  <B/>
  <C>...</C>
</A>

<Z>
  <B>
  <C>...</C>
</Z>

In the first case, I want to pick up the value of C and put it into my
output stream (because the parent element is A); in the second case I do not
(because the parent element is Z, not A).  Note that the following is also
legal input:

<Y>
  <A>
    <B/>
    <C>...</C>
  </A>
  <A>
    <B/>
    <C>...</C>
  </A>
</Y>

Note that this means that I cannot just refer to "../../A/C" in the B
template, because I could end up getting the value from the wrong C element.

I am currently using

"ancestor::*[1][name()='A']/C"

Of course my names aren't 'A' and 'C'; in fact they're *VERY* long, so this
quickly gets unwieldy.

This sure seems clumsy.  For the elegant, intuitive, language that XSLT is
supposed to be, surely there's a simpler way to do this?  I've tried using
'..' and '/' until I'm blue in the face, and gotten nowhere.

Any help will be appreciated.

Topher Eliot
Sr. Software Engineer
J.D. Edwards
Christopher_Eliot@jdedwards.com
303 334-2493


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]