Altova Mailing List Archives


[xsl] Complex XPath Help

From: "Peet, Mike" <MPeet@---------------->
To:
Date: 4/25/2002 11:48:00 AM
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

Disclaimer

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 www.altova.com/list/index.html. 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.