Xslt need to choose one quote
I need to do this:
<xsl:with-param name="callme" select="'validateInput(this,'an');'"/> I read Escape the single quote in the xslt concat function , and it tells me to replace ' with ' . I made it still work ..
Does anyone know how we will fix this?
<xsl:with-param name="callme" select="'validateInput(this,'an');'"/> Something simple that can be used in any version of XSLT :
<xsl:variable name="vApos">'</xsl:variable> I often use the same method to indicate a quote :
<xsl:variable name="vQ">"</xsl:variable> You can then traverse any of these variables into any text using the standard XPath concat() function:
concat('This movie is named ', $vQ, 'Father', $vApos, secrets', $vQ) So this conversion is :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:variable name="vApos">'</xsl:variable> <xsl:variable name="vQ">"</xsl:variable> <xsl:template match="/"> <xsl:value-of select= "concat('This movie is named ', $vQ, 'Father', $vApos, secrets', $vQ) "/> </xsl:template> </xsl:stylesheet> produces
This movie is named "Father secrets" In XSLT 2.0, you can use a character as a line separator, doubling it, so
<xsl:with-param name="callme" select="'validateInput(this,''an'');'"/> Another solution is to use variables:
<xsl:variable name="apos">'</xsl:variable> <xsl:variable name="quot">"</xsl:variable> <xsl:with-param name="callme" select="concat('validateInput(this,', $apos, 'an', $apos, ');')"/> It's a bit complicated, but you need to invert the apostrophe and quotes, for example:
<xsl:with-param name="callme" select='"validateInput(this,'an');"' /> You include the string in one set of quotation marks and the value of the attribute that contains it in another. In the XSLT that you are quoting, you are both interchangeable in both cases if you are not using the same one.
Earlier your ' was parsed when the value of the match attribute was read, and it tried to set the value select 'validateInput(this,'an');' . Although this is a technically valid string value when XSLT processes it, he cannot parse it because he is trying to read it as a string literal that ends prematurely before an , because it uses the same apostrophe as that used to nest the string.
Use "and not & (using &, you effectively place single quotes inside single quotes, you need to alternate single and double quotes as you are in the socket, escaping if necessary).