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

RE: How to use arrays in XSLT?

Subject: RE: How to use arrays in XSLT?
From: <Jarno.Elovirta@xxxxxxxxx>
Date: Wed, 29 Sep 2004 09:55:03 +0300
arrays in xslt
Hi,

> Can I use arrays in the XSLT program?

XPath doesn't have an array data type, but there are ways to get where you
want.

> I want to hold hundreds of (name,value) pairs in an array,,
> may be in 2 arrays
> 1st array ==> name
> 2nd array ===> value
>
> so that I can index on the name to get the value of that name...
>
> Is it possible in XSLT???

If you have a static array, then create something in the lines of

<x:map>
  <entry key="..." value="..."/>
  ...
</x:map>

and stick that inside xsl:stylesheet. Then define an xsl:key as

<xsl:key name="lookup" match="entry/@value" use="../@key"/>

and then do a look-up with

<xsl:variable name="key" select="get-key-value"/>
<xsl:for-each select="document('')">
  <xsl:value-of select=key('lookup', $key)"/>
</xsl:for-each>

There are other ways doing it, e.g. if you need to use a dynamic map or if you
use XSLT 2.0, but in that case you should describe your needs in more detail.
Hope this helps.

Cheers,

Jarno - Nick Sentience: March 2003 Mix

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.