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

Re: A smarter choose operation XSL 1.1

Subject: Re: A smarter choose operation XSL 1.1
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Wed, 10 Jun 2009 21:32:42 -0700
Re:  A smarter choose operation XSL 1.1
An XSLT 1.0 solution:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>

 <xsl:variable name="vrtfResults">
   <r>1</r>
   <r>1.70</r>
   <r>2.25</r>
   <r>3</r>
 </xsl:variable>

  <xsl:param name="optional.one" select="true()" />
  <xsl:param name="optional.two" select="true()" />
  <xsl:param name="optional.three" select="true()" />

	<xsl:template match="/">
	  <xsl:variable name="vResults" select=
	  "document('')/*/xsl:variable[@name='vrtfResults']/*"
	  />

	  <xsl:value-of select=
	  "$vResults[$optional.one
	           + $optional.two
	           + $optional.three
	           + 1
	            ]"/>
	</xsl:template>
</xsl:stylesheet>



--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play




On Wed, Jun 10, 2009 at 2:20 PM, Karl Stubsjoen<kstubs@xxxxxxxxx> wrote:
> I have 3 optional param values that are either true/false. B I need a
> solution which will return 4 different numbers when:
>
> 1) all param values are true
> 2) two param values are true
> 3) one param value is true
> 4) none are true
>
> I was about to write one big choose and then thought maybe there is a
> more efficient way of doing it. B So any ideas on this one? B For sake
> of discussion, here is a mock up of the template and param values I
> have:
>
> <xsl:template name="test">
> B <xsl:param name="optional.one" select="true()" />
> B <xsl:param name="optional.two" select="true()" />
> B <xsl:param name="optional.three" select="true()" />
>
> B <!--
> B  B Return:
>
> B  B When All, return 3.00
> B  B When Two, return 2.25
> B  B When One, return 1.70
> B  B When Zero, return 1.00
> B  -->
>
> </xsl:template/>
>
> Thanks for the help!
>
> Karl..

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.