0

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?

2
  • You have edited the sample and used the right parameter name in the reference $books, but I wonder why you only compare to $books[1] if you want to filter based on all items in your array. Commented Dec 2, 2014 at 10:11
  • I recognized the mistake when I read over the question. I changed it back in order to keep your correct answer :) thank you! Commented Dec 2, 2014 at 10:14

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.