Hi Marcel,
Sure! Before Koha started using "http://exslt.org/strings" to encode URIs, I used to use register_function to add my own function to do that. 1. vi C4/XSLT.pm 2. Add a line near the top like: a. XML::LibXSLT->register_function("http://wwww.prosentient.com.au/xsltperl", "uri-escape",\&Koha::Prosentient::Biblio::Urls::xslt_uri_escape); 3. Write a function like this: sub xslt_uri_escape { my ($uri) = @_; #$uri should always be a XML::LibXML::Nodelist, even if that Nodelist just contains 1 URI if (ref $uri eq "XML::LibXML::NodeList"){ $uri->foreach( sub { my ( $node ) = @_; #If the node has child (text) nodes if ($node->hasChildNodes()){ my @childNodes = $node->childNodes(); if (@childNodes){ foreach my $childNode (@childNodes){ if (my $textdata = $childNode->data){ #Trim whitespace $textdata =~ s/^\s+|\s+$//g; my $encoded_url = URI::Encode::uri_encode($textdata, { encode_reserved => 0 }); if ($encoded_url){ #Replace the existing URI data with the encoded URI data $childNode->setData($encoded_url); } } } } } } ); } return $uri; } 4. Add the namespace at the top of your XSLT: a. xmlns:pro="http://wwww.prosentient.com.au/xsltperl" 5. Call the function on some XML: a. <xsl:value-of select="pro:uri-escape(//marc:datafield[@tag=856]/marc:subfield[@code='u'])" /> -- More recently, I've done more complicated things like looking up item urls for that biblio record, deduplicating them against the 856$u, and adding them to the online access in the search results. I continue to take into account OpacHiddenItems and its associated preferences. Since it's operating at the Perl level, I'm able to check the C4::Context->userenv for the patron details as well. David Cook Senior Software Engineer Prosentient Systems Suite 7.03 6a Glen St Milsons Point NSW 2061 Australia Office: 02 9212 0899 Online: 02 8005 0595 From: Marcel de Rooy <m.de.r...@rijksmuseum.nl> Sent: Friday, 8 March 2024 6:13 PM To: 'Koha Devel' <koha-devel@lists.koha-community.org>; David Cook <dc...@prosentient.com.au> Subject: Re: [Koha-devel] Random XSLT knowledge Hi David, Thanks for sharing. Would you have an example of how you use register_function with Koha functions to share? Marcel _____ Van: Koha-devel <koha-devel-boun...@lists.koha-community.org <mailto:koha-devel-boun...@lists.koha-community.org> > namens David Cook via Koha-devel <koha-devel@lists.koha-community.org <mailto:koha-devel@lists.koha-community.org> > Verzonden: vrijdag 8 maart 2024 03:02 Aan: 'Koha Devel' <koha-devel@lists.koha-community.org <mailto:koha-devel@lists.koha-community.org> > Onderwerp: [Koha-devel] Random XSLT knowledge Hi all, I've been working on performance issues, and in the process I got looking at XSLTs. I just wanted to share that it's possible to pass strings to the XSLT's transform() method: - return $engine->transform($xmlrecord, $xslfilename ); #file or URL + return $engine->transform({ + xml => $xmlrecord, + file => $xslfilename, + parameters => { + test => "'$test_str'", + }, + }); #file or URL It's somewhat limited in that you can only pass strings and I think there's a small limit on the number of parameters you can pass (not sure if it's 32 or 255), but I thought it was interesting. It would allow you to pass some data that you have at hand on a per-XML record basis without having to mangle the XML record (like we do with items and system preferences). In the end, I didn't end up using it though. Instead, I use XML::LibXSLT->register_function() to provide access to Koha functions from the XSLT, and in this case that meets my needs. Anyway, back to it.. David Cook Senior Software Engineer Prosentient Systems Suite 7.03 6a Glen St Milsons Point NSW 2061 Australia Office: 02 9212 0899 Online: 02 8005 0595
_______________________________________________ Koha-devel mailing list Koha-devel@lists.koha-community.org https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel website : https://www.koha-community.org/ git : https://git.koha-community.org/ bugs : https://bugs.koha-community.org/