Bug 13262 - Add parameters to XSLT Handler transform method
authorDavid Cook <dcook@prosentient.com.au>
Mon, 17 Nov 2014 02:59:49 +0000 (13:59 +1100)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Thu, 5 Feb 2015 18:24:29 +0000 (15:24 -0300)
commitd3c128af9d4e3890cf6cf84fc4bf2c1fc4f9d24c
tree76a2da8a824a075615873dbe218966ba6fd27609
parent41181b27087b1b547e8a487afc3207e9677fab6d
Bug 13262 - Add parameters to XSLT Handler transform method

This patch adds an optional hashref argument to the XSLT_Handler
transform() method. It allows you to send key => value pairs
parameters to the XML::LibXSLT object, which you can reference
in a XSLT via <xsl:param name="XXX" />.

The parameter value is evaluated as an XPath query, so you can only
pass quoted strings (i.e. "'test'") or numbers. Otherwise, the
XSLT engine will interpret it as a Xpath query and will run it
on the XML that you're transforming.

The most common use case is sending strings to a XSLT. In my case,
this is an OAI-PMH identifier that comes in a OAI response but not
the actual metadata. See the following link from the official POD:
http://search.cpan.org/~shlomif/XML-LibXSLT-1.92/LibXSLT.pm#Parameters

_TEST PLAN_

1) Run "perl t/db_dependent/XSLT_Handler.t". If all tests pass,
you should be free to sign off. Feel free to inspect the last
test in XSLT_Handler.t and the XSL in test04.xsl to see how it
works.

If you really want to be thorough, you could write your own test
cases using mine as an example.

Alternatively, you could go into C4::XSLT, and try to pass a
value to a parameter in the search results or the detail page,
but that might be a bit over the top.

It's a pretty simple patch.

Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Koha/XSLT_Handler.pm
t/db_dependent/XSLT_Handler.t
t/db_dependent/XSLT_Handler/test04.xsl [new file with mode: 0644]