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

RE: Best way to create a "dictionary"/"map"/"something

Subject: RE: Best way to create a "dictionary"/"map"/"something"
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Tue, 18 Jun 2002 14:22:03 +0100
dictionary map
The simplest way is to create a temporary tree and use xx:node-set() to
do the lookup:

<xsl:variable name="dict">
<entry key="k1" value="v1"/>
<entry key="k2" value="v2"/>
</xsl:variable>

xx:node-set($dict)/entry[@key=$x]/@value

or use xsl:key for faster access if the table is large.

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

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Antonio Fiol
> Sent: 18 June 2002 09:20
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Best way to create a "dictionary"/"map"/"something"
> 
> 
> Hello,
> 
> Here is the idea: In french, dates are written as DD MMMM YYYY. So, I 
> have an element with the parameters day, month and year (as numbers, 
> from 1 to whatever) and my named template "from-to" should output 
> something like "du 3 février 2001 au 6 octobre 2002" being 
> "du" and "au" 
> the french words for "from" and "to".
> 
> So, my template looks like this:
> 
>  <xsl:template name="from-to">
>    du
>    <xsl:value-of 
> select="/doc/generator/dateform[@prefix='start']/@day" />
>    <xsl:call-template name="month">
>        <xsl:with-param name="month" 
> select="/doc/generator/dateform[@prefix='start']/@month" />
>    </xsl:call-template> <xsl:value-of 
> select="/doc/generator/dateform[@prefix='start']/@year" />
>    au
>    <xsl:value-of 
> select="/doc/generator/dateform[@prefix='end']/@day" />
>    <xsl:call-template name="month">
>        <xsl:with-param name="month" 
> select="/doc/generator/dateform[@prefix='end']/@month" />
>    </xsl:call-template>
>    <xsl:value-of 
> select="/doc/generator/dateform[@prefix='end']/@year" />  
> </xsl:template>
> 
> And here is what I use to map numbers to their corresponding texts.
> 
>  <xsl:template name="month">
>   <xsl:param name="month" />
>   <xsl:choose>
>    <xsl:when test="$month=1">janvier</xsl:when>
>    <xsl:when test="$month=2">février</xsl:when>
>    <xsl:when test="$month=3">mars</xsl:when>
>    <xsl:when test="$month=4">avril</xsl:when>
>    <xsl:when test="$month=5">mai</xsl:when>
>    <xsl:when test="$month=6">juin</xsl:when>
>    <xsl:when test="$month=7">juillet</xsl:when>
>    <xsl:when test="$month=8">août</xsl:when>
>    <xsl:when test="$month=9">septembre</xsl:when>
>    <xsl:when test="$month=10">octobre</xsl:when>
>    <xsl:when test="$month=11">novembre</xsl:when>
>    <xsl:when test="$month=12">décembre</xsl:when>
>   </xsl:choose>
>  </xsl:template>
> 
> Even if this looks as a date formatting problem, it is not. I 
> have other 
> "dictionaries" like the following:
> 
>  <xsl:template name="access-mode">
>   <xsl:param name="bps"/>
>   <xsl:choose>
>    <xsl:when test="$bps=3600">Modem 28K</xsl:when>
>    <xsl:when test="$bps=4200">Modem 33K</xsl:when>
>    <xsl:when test="$bps=7075">Modem 56K</xsl:when>
>    <xsl:when test="$bps=8000">RNIS 64K</xsl:when>
>    <xsl:when test="$bps=16000">RNIS 128K</xsl:when>
>    <xsl:when test="$bps=32000">ADSL 256K</xsl:when>
>    <xsl:when test="$bps=64000">ADSL 512K</xsl:when>
>    <xsl:when test="$bps=96000">Cable 768K</xsl:when>
>    <xsl:when test="$bps=128000">ADSL 1M</xsl:when>
>    <xsl:when test="$bps=256000">ADSL 2M</xsl:when>
>   </xsl:choose>
>  </xsl:template>
> 
> Is this the best solution?
> Is there a better one?
> 
> N.B. All the options are known when I write the XSL file.
> 
> 
> Thank you very much.
> 
> 
> Antonio Fiol
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 


 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.