This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: 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