3

I am passing an arraylist from Java to Xsl using transformer.setParameter.

ArrayList books=new ArrayList<String>;
transformer.setparameter("booksinXSL","books");

Now I need to access this array's elements in XSL.

<xsl:param name="booksinXSL">

Now If I use this line of code in XSL it throws an error:Invalid conversion of ArrayList to NodeSet.

<value-of select="$booksinXSL[0]">

but if I set it as the below line it prints the entire array [book1,book2] without any error

<value-of select="$booksinXSL">
Michael Kay
  • 156,231
  • 11
  • 92
  • 164
Abishek
  • 31
  • 1
  • 3
  • 1
    Which XSLT processor are you using? The reference to "NodeSet" in the error messaage suggests it's a 1.0 processor, but you have tagged the question XSLT-2.0. Note that mappings from Java types to XPath types are not defined by any standard, they vary from one XSLT processor to another. – Michael Kay Aug 24 '14 at 13:58
  • Thanks Michael. I am using XSLT 1.0. – Abishek Aug 25 '14 at 17:16
  • I've edited your question to remove the misleading xslt-2.0 tag. But it remains true that there are several Java-based XSLT 1.0 processors, and mapping from Java to XPath/XSLT types depends on which one you are using. – Michael Kay Aug 25 '14 at 19:02
  • What **exactly** are the contents of the parameter? -- P.S. Note that in XSLT, nodes are numbered starting from 1, so `select="$node-set[0]"` will never select anything. But that's not likely the problem here, since you are getting an error. – michael.hor257k Aug 25 '14 at 20:00

1 Answers1

2

XSL does not have the concept on arrays defined, but you can define a variable to contain a set of nodes and then iterate through these nodes. You can see a useful example at this page.

Community
  • 1
  • 1
gpu3d
  • 1,164
  • 1
  • 10
  • 21
  • Iteration is not possible as I mentioned in the question if u pass an array from java to xslt using transformer.setparameter method. – Abishek Aug 25 '14 at 17:17
  • You need to iterate through the set of nodes after you have passed the array. – gpu3d Aug 25 '14 at 21:14