How to pass a string containing both single and double quotes as a parameter to XSLT in PHP?

Posted by Boaz on Stack Overflow See other posts from Stack Overflow or by Boaz
Published on 2010-04-29T11:50:29Z Indexed on 2010/04/29 12:37 UTC
Read the original article Hit count: 407

Filed under:
|
|
|
|

Hi,

I have a simple PHP-based XSLT trasform code that looks like that:

$xsl = new XSLTProcessor();
$xsl->registerPHPFunctions();
$xsl->setParameter("","searchterms", $searchterms);
$xsl->importStylesheet($xslDoc);
echo $xsl->transformToXML($doc);

The code passes the variable $searchterms, which contains a string, as a parameter to the XSLT style sheet which in turns uses it as a text:

<title>search feed for <xsl:value-of select="$searchterms"/></title> 

This works fine until you try to pass a string with mixes in it, say:

$searchterms = '"some"'." text's quotes are mixed."

In that point the XSLT processor screams:

Cannot create XPath expression (string contains both quote and double-quotes)

What is the correct way to safely pass arbitrary strings as input to XSLT? Note that these strings will be used as a text value in the resulting XML and not as an XPATH paramater.

Thanks, Boaz

© Stack Overflow or respective owner

Related posts about xslt

Related posts about php