Re: Passing arrays into XSL
Hi Jern, Thanks for your help. But my need is bit different, we have to match with the strings from the variable or the parameter from a servlet response. So i need to match those strings available in the 'param' with actual xml file. The xml file nodes may be more than blue,red colors. So the XSL display should be depends on the values available in the param. The parameter string may be with a delimiter ','(red, blue) or '' (red blue). <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="arrayString"> blue,red </xsl:param> <xsl:template match="colors"> <xsl:if test="contains(color,$arrayString)"> <xsl:text> do something</xsl:text> </xsl:if> </xsl:template> </xsl:stylesheet> Please let me is the'r anything left behind. Thanks, Deepak --- Joern Nettingsmeier <nettings@xxxxxxxxxxxxxxxxxxxxxx> wrote: > 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 > > > > <colors> > > <color>color<color> > > <color>color<color> > > <color>color<color> > > </colors> > > 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: > > <colors> > <color>blue</color> > <color>red</color> > <color>an obnoxious shade of pink</color> > </color> > > <xsl:template match="colors/color"> > <xsl:value-of select="."/> > </xsl:template> > > 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> > </xsl:template> > > > 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 > > > > -- > jvrn nettingsmeier > > home://germany/45128 essen/lortzingstr. 11/ > http://spunk.dnsalias.org > phone://+49/201/491621 > > 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 > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format