Hi Aron,
On Thu, May 19, 2005 at 12:41:15PM +0000, Aron Bock wrote:
If <outcomes:columns> is the shorter list, you may want to iterate
just that, at the appropriate junction. Theoretically that should
lessen wasted work.
I see---inside the template matching 'row', iterate over the values of
the 'attName' attributes in the 'column' elements and pull out the
values of the attributes with those names. You're right, I suppose
that would be the minimum amount of work for a nested iteration like
this, but it's still O(n^2) in terms of pulling nodes out of the
source.
I guess I wanted something like this pseudocode:
if attribute-name is in list-of-attribute-names
output attribute-value
Where list-of-attribute names is generated once in advance. Then it
would be just O(n) where n is the number of rows.
Alternatively you could let XSL do the lifting for you. Something
like so:
With this imput (yours, simplified):
<data>
<outcomes>
<column attName="Computer" displayName="Computer Used" sum="no" />
<column attName="Location" displayName="The Location" sum="no" />
</outcomes>
<rows>
<row Computer="Rohan's PC" Location="IT Dept" Duration="555" />
<row Computer="Pharmacy" Location="Pharmacy" Duration="457" />
</rows>
</data>
This XSL:
<?xml version="1.0" encoding="iso8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="data/rows/row">
<xsl:for-each select="@*[name() =
/data/outcomes/column/@attName]">
<xsl:value-of select="."/>
<xsl:text>, </xsl:text>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Produces:
Rohan's PC, IT Dept,
Pharmacy, Pharmacy,
That's getting closer to what I want, at least in terms of neatness.
I'm just wondering if we can get rid of the nested for-each.
I suppose you could use keys for faster access, but I don't know how
that would affect total transform time.
You're right, I guess the question is "does this affect the transform
time?" Even the nested for-each constructs don't seem to, probably
because the input is only of the order of hundreds or a few thousand
rows in my case. I was just wondering whether there is an idiom in
XSL that is analogous to my pseudocode above. I can't seem to hit on
it myself.
--
Paul.
w http://logicsquad.net/
h http://paul.hoadley.name/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--