Reputation: 299
I have an XML File what I want to transform with Saxon-CE XSLT 2.0 Processor:
<books>
<book name="book1">
<book name="book2">
<book name="book3">
</books>
I want to filter this XML file by an array. This array is the result of selected checkboxes of a webpage and is passed to the XSLT with setParameter:
$("input:checkbox[id='books']" ).each(function() {
books.push($(this).val());
});
//books: ["book1", "book2"]
xslt = Saxon.requestXML("xsltfile.xsl");
xml = Saxon.requestXML("xmlfile.xml");
var xsltProc = Saxon.newXSLT20Processor(xslt);
xsltProc.setParameter(null, "books", books);
Now I want to select all books where the name occurs in the array.
XSLT:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="books"></xsl:param>
<xsl:variable name="mybooks" select="/books/book[@name=$param[1]]"/>
</xsl:stylesheet>
How can I loop over the array and select only the books with the name of the array?
Upvotes: 0
Views: 970
Reputation: 167506
In case of
<xsl:param name="books"></xsl:param>
<xsl:variable name="mybooks" select="/books/book[@name=$param]"/>
you would need
<xsl:param name="books"></xsl:param>
<xsl:variable name="mybooks" select="/books/book[@name=$books]"/>
Other than that I don't see anything wrong in your code and according to http://saxonica.com/ce/user-doc/1.1/index.html#!api/xslt20processor/setParameter a parameter value can be a Javascript array, so hopefully that interaction between Javascript and XSLT works.
Upvotes: 1