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

RE: efficient if/else

Subject: RE: efficient if/else
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Mon, 6 May 2002 21:29:03 +0100
if e if else
> I have something like the following:
>
> <Product>
>       <e1 Action = "A"/>
>       <e2 Action = "A"/>
>       <e3 Action = "A"/>
>       <e4 Action = "A"/>
>       <e5 Action = "A"/>
>       <more1>
>             <stuff Action = "(Could be anything)"/>
>       </more1>
>       <more2>...</more2>
>       ...
> </Product>
>
> I am interested in the most efficient way of going through the first 5
> elements and looking at the Action attribute.
>

<xsl:variable name="E" select="*[starst-with(name(), 'e')]"/>
<xsl:choose>
> If any is an "M", I will output an "M".

<xsl:when test="$E='M'">M</xsl:when>

> If they are all "A", I will output "A".

<xsl:when test="not($E != 'A')">A</xsl:when>

> If they are all "D", I will output "D".

<xsl:when test="not($E != 'D')">D</xsl:when>

> Any mixture of "A" and "D" should output an "M".

<xsl:when test="$E='A' and $E='D'">M</xsl:when>
>
> Another twist is that any of the "e elements" (e1, e2,
> e3,...) may or may
> not be present.  If present, the Action attribute will always
> be present.
>
> I obviously don't want to have an n! search.
>
It's likely that each of these tests will involve a linear search of the e*
elements. If you want something faster than that, you could use keys.

Note that the condition all exploit the "existential equals": $E = 'X' is
true if any node in E equals 'X'. The inversion of this, not($E != 'X') is
true if there is not a $E that is not equal to 'X', i.e. if every E equals
'X'.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.