Subject: RE: [xsl] sliding window of depth 2 From: "Américo Albuquerque" <aalbuquerque@xxxxxxxxxxxxxxxx> Date: Fri, 2 Aug 2002 12:28:08 +0100 |
Hi Fiol, thanks for your reply. Relative to your first question, something like that, i expect to apply-templates to the nodes with id=1, id=3 and id=4. the 'node' node is allways the first one to be displayed, but the it will junp the node with id=2 and start with id=3 the node counts to de limit when it appears in the middle, some thing like this: (i'll use caps-lock to distinguish between the node named Node and node reference) start=1&qnt=3 source: <doc> <NODE id=1> <book id=2> <book id=3> <book id=4> </NODE> <NODE id=5> <book id=6> <book id=7> </NODE> </doc> result(example in plain text): ___________________first window start=1&qnt=3 <NODE id=1>(line1) <book id=2>(line2) <book id=3>(line3) ___________________next window start=4&qnt=3 <NODE id=1> <book id=4> <NODE id=5> ___________________next window start=5&qnt=3 <NODE id=5> <book id=6> <book id=7> i thought about that problem last night and come with something like this: <xsl:for-each select="node|node/book"> <xsl:apply-templates select="."/> </xsl:for-each> this will give me the nodes that i want. what i do not know is if i can do something like select="(node|node/book)[position()>=$start and position()<($star+$QNT)]" can this be done?? about grouping.. well, not exactly, each (node|node/book) will on consecutive lines, i need the $start and the QNT so that i can delemite (i dont know if this is the wright word for that) the number of (node|node/book) that will be displayed. thanks -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Antonio Fiol Bonnín Sent: Thursday, August 01, 2002 8:50 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] sliding window of depth 2 I do not provide a solution, but let me attract your attention to the following point: With following input: <doc><node id="1"><book id="2"/><book id="3"/></node><node id="4"><book id="5"/></node></doc> And provided that start=3 and qty=2, what would you expect your output to be? From your description, you expect to apply-templates to the nodes with id 3 and 4. I believe you do not really want that, do you? I imagine that you want that with start=2 and qty=2 you get two tables with one row each. That is, you are not counting elements at two levels, but only at one level, which happens to be the second. Apart from that, you need grouping. into tables, and that is another matter. So the nodes you are selecting on are: node/book[position() >= $start and position() < ($qty + $start)] I would group using the first ones on the group: node/book[position() >= $start and position() < ($qty + $start)][not(preceding-sibling::book)] And then, process all the groups in two phases, all but the last, and the last. The last is different because not all following siblings of the first book element are to be in the output. So we will need to somehow calculate how many of them to output. I would bet for something like: <xsl:apply-templates select="node/book[position() >= $start and position() < ($qty + $start)][not(preceding-sibling::book)][position() < last()]" mode="group" /> <xsl:apply-templates select="node/book[position() >= $start and position() < ($qty + $start)][not(preceding-sibling::book)][last()]" mode="lastgroup"> <xsl:with-param name="remain" select="$qty - count(node/book[position() >= $start and position() < ($qty + $start)][not(preceding-sibling::book)][position() < last()]) - count(node/book[position() >= $start and position() < ($qty + $start)][not(preceding-sibling::book)][position() < last()]/following-sibling::book)" /> </xsl:apply-templates> <xsl:template match="book" mode="group"> <table> <xsl:apply-templates select=". | following-sibling::book" /> </table> </xsl:template> <xsl:template match="book" mode="lastgroup"> <xsl:param name="remain" select="1" /> <table> <xsl:apply-templates select="." /> <xsl:apply-templates select="following-sibling::book[position() < $remain" /> </table> </xsl:template> None of these lines of code are tested. I hope you get the idea, and especially that the idea is good, which I am not sure at all... Antonio Fiol Américo Albuquerque wrote: >Hi! > >I have a xml file with this structure: ><doc> > <node> > <book/> > <book/> > ... > </node> > <node> > <book> > ... > </node> > ... ></doc> >I aplly to it this stylesheet > ><xsl:template match="doc"> > <xsl:apply-templates select="node[position()>=$start and >position()<$start+$QNT]"/> </xsl:template> > ><xsl:template match="node"> > <table> > <xsl:apply-templates/> > </table> ></xsl:template> > ><xsl:template match="book"> > <tr> > <td>(some text here) </td> > </tr> ></xsl:template> > >and I want to make a sliding window, i.e., I want to show $QNT nodes >each time strating at $start. this stylesheet does that but only to the >node nodes, i.e., it shows up to $QNT node, starting at $start, but I >also want to include the books on that count. > >for example: >if start= 5 and QNT=10 then I want to apply the templates to the 10 >(node|node/book) after the first 5 (node|node/book) > >thanks in advance. > >Américo Albuquerque > > > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > >. > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] sliding window of depth 2, Antonio Fiol Bonnín | Thread | [xsl] XML to html, Mridula Mahadevan |
RE: [xsl] Re:, aruniima . chakrabar | Date | [xsl] how to get position(), Vinoth Palaniappan |
Month |