[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Testing if an attribute name is in a list of names

Subject: Re: Testing if an attribute name is in a list of names
From: "Paul A. Hoadley" <paulh@xxxxxxxxxxxxxx>
Date: Thu, 19 May 2005 22:38:55 +0930
attribute n
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>&#xa;</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/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.