Re: [xsl] Passing arrays into XSL

Subject: Re: [xsl] Passing arrays into XSL
From: Joern Nettingsmeier <nettings@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 26 Feb 2006 01:11:14 +0100
hi deepak!

i missed the beginning of this thread (new to this list), but i'll try an answer:

Deepak wrote:
I am bit new to XSL processing.  If we can't pass the
arrays into XSL, then i hope that we can pass array
string as a variable.

Say i have an XML file


are those square brackets just meant as an example, or are you thinking about the array syntax of other languages?

xsl does not have the notion of indexed arrays. the square brackets you will see in xpath statements are *predicates* that will select from a node-set.

what you could do is this:

  <color>an obnoxious shade of pink</color>

<xsl:template match="colors/color[2]">
  <xsl:value-of select="."/>

this will produce "red" as an output, since it's the second <color> element.

if you want to check whether "blue" is in the list of colors, you can do

<xsl:template match="colors/color[text() = 'blue']">
  <xsl:text>Your color list contains "blue".</xsl:text>

generally, square brackets can mean two things:

(1) from a set of nodes, select those for which the expression in the square brackets is true;
(2) if the expression in square brackets produces not a boolean but a number n, return the nth node from the set.

hope that helps,


jvrn nettingsmeier

home://germany/45128 essen/lortzingstr. 11/

if you are a free (as in "free speech") software developer
and you happen to be travelling near my home, drop me a line
and come round for a free (as in "free beer") beer. :-D

Current Thread