Subject: Re: [xsl] Complex XPath Help From: Joerg Heinicke <joerg.heinicke@xxxxxx> Date: Thu, 25 Apr 2002 22:12:42 +0200 |
<xsl:template match="tab"> <xsl:text>preceding page:</xsl:text> <xsl:value-of select="preceding::tab/@page"/> <xsl:text>current page:</xsl:text> <xsl:value-of select="@page"/> <xsl:text>next page:</xsl:text> <xsl:value-of select="following::tab/@page"/> </xsl:template>
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Complex XPath Help, Peet, Mike | Thread | RE: [xsl] Complex XPath Help, Michael Kay |
[xsl] Complex XPath Help, Peet, Mike | Date | Re: [xsl] Complex XPath Help, Christopher R. Maden |
Month |