Connecting Tech Pros Worldwide Help | Site Map

outputting Pairs of Nodes

awebguynow
Guest
 
Posts: n/a
#1: Dec 29 '05
I know its redundant but thats what this report calls for.
For every node except the first, I want to output a pair of nodes: the
current and prev one.
For sake of example, lets call the node <qsales> Quarterly Sales. (and
includes children)

If I could use an array syntax, it would be:
<qsales>[1]
<qsales>[2]

<qsales>[2]
<qsales>[3]

<qsales>[3]
<qsales>[4]

So I'm playing with preceding-sibling and hoping PHP5 is using XSLT
2.0 ie: max()
libxslt Version 1.1.7 phpinfo() notes
libxslt compiled against libxml Version 2.6.11 phpinfo() notes

Actually, doing some CL tests on WinXP, using jdk1.4.0
I'll have to research to find out what lib is being used there.

right now, I'm using a sort and then attempting something like this
(psuedo-code)
<xsl:variable name="ndx" select="position()" /> // having problems
defining var in root template
call-template <xsl:with-param name="node" select="." />
call-template <xsl:with-param name="node"
select="../qsales[position()=$ndx-1]" />

Another alternative, as I brainstorm
could I find the max() position() of preceding-sibling ?

One of the children of the nodes, is actually an index, but I'm
doubtful I can use it
Select node where <qsales>.index = 3 then use call-template

Re: Outputting Pairs - can I get a little help ?

Peter Flynn
Guest
 
Posts: n/a
#2: Dec 29 '05

re: outputting Pairs of Nodes


awebguynow wrote:
[color=blue]
> I know its redundant but thats what this report calls for.
> For every node except the first, I want to output a pair of nodes: the
> current and prev one.
> For sake of example, lets call the node <qsales> Quarterly Sales.
> (and includes children)
>
> If I could use an array syntax, it would be:
> <qsales>[1]
> <qsales>[2]
>
> <qsales>[2]
> <qsales>[3]
>
> <qsales>[3]
> <qsales>[4]
>
> So I'm playing with preceding-sibling[/color]

<xsl:if test="position()>1">
<xsl:value-of select="preceding-sibling::qsales[1]"/>
</xsl:if>

A numeric abbreviated predicate on a 'preceding' axis counts backwards
from the context node, so [1] here means the immediately preceding
element node of the given type.

///Peter
--
XML FAQ: http://xml.silmaril.ie/

Closed Thread