Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CASE or IN Function? 1

Status
Not open for further replies.

Bilberry

Programmer
Dec 17, 2007
111
NL
Is there a CAST or a look a like of a SELECT ... IN function? Im now using the When and then function like:

<xsl:when test="Fields/Field[@Name='test']='1'">123</xsl:when>
<xsl:when test="Fields/Field[@Name='test']='2'">123</xsl:when>

Like example above, but i have i think 40 values which i need to evaluate and most of them does have only 1 value, like when its 1,2,3,4,5,6,7,8 then the field should be 123 when its 9 then it should be 456, is there a simply way to write a case structure or something similar like that?

TIA
 
[tt]<xsl:when test="number(Fields/Field[@Name='test']) &lt;= 9">123</xsl:when>
<xsl:eek:therwise>456</xsl:eek:therwise>
<!-- or: depending on the need
<xsl:when test="number(Fields/Field[@Name='test']) &gt; 9">456</xsl:when>
-->
[/tt]
 
Hi Tsuji,

Thanks a lot for your reply, but my example was only a dummy example :). Normally i have other values. Is there something like:

<xsl:when test="Fields/Field[@Name='test']='1', '2', '8', '16'">123</xsl:when>


Any Idea?
 
If the enumeration of acceptance set follows apparant pattern numeric, you can make up your own look up table in the xsl document. (The namespace and its prefix are absolutely arbitrary - you don't have to follow my demo.)
[tt]
<xsl:stylesheet version="1.0" xmlns:xsl="[ignore][/ignore]"
[blue]xmlns:sdl="urn:self-doc:lookup"[/blue]>
<!-- all the existing script... -->

<!-- somewhere within it appears the xsl:when -->
<xsl:when test="Fields/Field[@Name='test']=document('')/xsl:stylesheet/sdl:table/entry">123</xsl:when>
<xsl:eek:therwise>456</xsl:eek:therwise>
<!-- continue with the rest... -->

[blue]<sdl:table>
<entry>1</entry>
<entry>2</entry>
<entry>8</entry>
<entry>16</entry>
<entry>xyz</entry>
<entry> <!-- etc etc whatever you need -->
</sdl:table>[/blue]

</xsl:stylesheet>[/tt]
 
Amendment
[1] Upon re-read what I posted, I should have namespaced the entry as well if not for the necessity but for coherence of construction...
[tt]
<sdl:table>
<[red]sdl:[/red]entry>1</[red]sdl:[/red]entry>
<sdl:entry>2</sdl:entry>
<sdl:entry>8</sdl:entry>
<sdl:entry>16</sdl:entry>
<sdl:entry>xyz</sdl:entry>
<sdl:entry> <!-- etc etc whatever you need -->
</sdl:table>
[/tt]
and then the test be scripted accordingly.
[tt]
<xsl:when test="Fields/Field[@Name='test']=document('')/xsl:stylesheet/sdl:table/[red]sdl:[/red]entry">123</xsl:when>
[/tt]
[2] The first senstence is broken.
>[self]If the enumeration of acceptance set follows some apparant pattern numeric, you can use parallel number functions, if possible, in the xpath, otherwise, if there is no apparent pattern string or numeric, or the numeric functions are complicated or transcendental, or a mix of different types, you can make up your own look up table in the xsl document.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top