xsl-list
[Top] [All Lists]

RE: Incrementing position in the tree midstream (Part 3)

2004-04-16 08:41:42
-----Original Message-----
From: Durston, Andrew (AGRE)


How would that be written?

      count(following::objecttext[.= 'string1' & 'string2']) ??


Hi,

Hmm. Would be more like:

count( following::objecttext[(.='string1') or (.='string2')] )

if you want to count the number of following objecttext nodes that have
'string1' or 'string2' as content.

If the '&' signifies a concatenation, simply use
count(following::objecttext[.=concat('string1','string2')])

However:
And once I have the count, I use that in a for-each from '.' to
following less than count, to output the cells?

      <xsl:for-each select=". |
following::objecttext[position()&lt; <<insert count command here
or a variable??>>]">

The above calculated number will bear no relation to the set of nodes
selected in the for-each, unless you write it like:

<xsl:for-each select=". |
                following::objecttext[(.='string1') or (.='string2')][
                  position() &lt; $varcount]">

Let's say there are 5 nodes counted by the count() expression (5 nodes
following the current node, and whose content is 'string1' or 'string2').
From *all* following objecttext nodes, you will select only the first 4 and
the current node. Does this sound like what you intend to do?

If not, maybe we'd better start again 'from the top'. Can you post a reduced
sample of the XML, and clarify how you would like to see it transformed?
(mainly the mentioned 'field' tabletype remains a mystery to the list: where
does it appear in the XML? As attribute? Or as child node? Of object or
objecttext?)

I have the feeling there is a more efficient solution than having to
traverse the following-axis for all objecttext nodes, but I really need to
know the exact structure of the XML in order to come up with something
that's definitely useful...

As a further tip:

<xsl:for-each select="nodes">
  <xsl:copy-of select="." />
</xsl:for-each>

is actually the same as:

<xsl:copy-of select="nodes" />

The only difference is that on the above, you could add an xsl:sort, but
that could also be solved like:

<xsl:apply-templates select="nodes">
  <xsl:sort select="@attr" />
</xsl:apply-templates>
...
<xsl:template match="nodes">
  <xsl:copy-of select="." />
</xsl:template>



Cheers,

Andreas



<Prev in Thread] Current Thread [Next in Thread>