[xsl] Complex XPath Help

Subject: [xsl] Complex XPath Help
From: "Peet, Mike" <MPeet@xxxxxxxxxxxxxxxx>
Date: Thu, 25 Apr 2002 15:48:58 -0400
Okay, it's probably not *that* complicated, but I'm having some trouble with
this one.  I think I'm missing something fundamental.  Sorry for the long
message.  For those of you that have the patience to look at this, your help
is greatly appreciated.

<xml>
   <tab-groups>
      <tab-group id="100" name="group1">
         <tabs>
            <tab desc="Page 1" page="page1.asp"/>
            <tab desc="Page 2" page="page2.asp"/>
         </tabs>
      </tab-group>
      <tab-group id="104" name="group2">
         <tabs>
            <tab desc="Page x" page="pagex.asp"/>
            <tab desc="Page y" page="pagey.asp"/>
         </tabs>
         <tab-group id="145" name="group3">
            <tabs>
               <tab desc="Page A" page="pageA.asp"/>
               <tab desc="Page B" page="pageB.asp"/>
            </tabs>
         </tab-group>
         <tab-group id="167" name="group3">
            <tabs>
               <tab desc="Page A" page="pageA.asp"/>
               <tab desc="Page B" page="pageB.asp"/>
            </tabs>
         </tab-group>
      </tab-group>
   </tab-groups>
</xml>

With the above XML document, if I pass a "page" into the XSLT as a
parameter, and I want to know what the previous and next pages are, how
would that be done?  Note that the tab-groups may be nested.

The desired behaviour is that the previous page would be simply the page
attribute of the preceding <tab> element (in document order, regardless of
group), and next would be the page attribute of the following <tab> element
(in document order, regardless of group).  The special cases of first and
last pages can return nothing.

One way that I can think of is an intermediate transform to get a document
containing just the <tab> elements with no nesting, and using the
preceding-sibling and following-sibling axes off the current tab, like this:

<xml>
   <tabs>
      <tab group-id="100" desc="Page 1" page="page1.asp"/>
      <tab group-id="100" desc="Page 2" page="page2.asp"/>
      <tab group-id="104" desc="Page x" page="pagex.asp"/>
      <tab group-id="104" desc="Page y" page="pagey.asp"/>
      <tab group-id="145" desc="Page A" page="pageA.asp"/>
      <tab group-id="145" desc="Page B" page="pageB.asp"/>
      <tab group-id="167" desc="Page A" page="pageA.asp"/>
      <tab group-id="167" desc="Page B" page="pageB.asp"/>
   </tabs>
</xml>

But this seems to defeat the purpose of a having a nice structured XML
document in the first place.  I would like to be able to accomplish this
without another transform, but I cannot seem to come up with the correct
XPath.. :(

Well, back to the XSL; thanks in advance!

Michael Peet
Software Engineer
Choice One Communications
100 Chestnut Street, Suite 600
Rochester, NY 14604
mpeet@xxxxxxxxxxxxxxxx
(585) 530-2773

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


Current Thread