Reputation: 2656
I would like to use double quotes in my XSLT, but I am getting error:
<xsl:param name="unsorted-values" as="xs:string*"
select=" 'Test 1','Test 1 with quote 21"' "/>
Obviously it is not working like this, because of double quote in the string. I tried to escape like 'Test 1 with quote 21\"'
, but it is not worked. Is there any way to use double quote in this way?
Upvotes: 0
Views: 168
Reputation: 167781
Inside of an XML attribute delimited by double quotes you can use the entity reference "
(or the appropriate numeric character reference).
Inside of an XSLT/XPath 2 or 3 string literal delimited by single quotes you can use two single quotes e.g. ''''
to have a single quote inside. Or if the string literal delimiter are double quotes you can double them inside e.g. """"
to have a string with a double quote.
A complete example with various options is
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="3.0">
<xsl:param name="s1" as="xs:string*"
select="'string with single quote: ''',
"string with double quote: """,
'string delimited by single quotes with single quote: '' and double quote: "',
"string delimited by double quotes with single quote: ' and double quote: """"/>
<xsl:template match="/*">
<xsl:copy>
<xsl:value-of select="$s1" separator=" "/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
outputting
<root>string with single quote: '
string with double quote: "
string delimited by single quotes with single quote: ' and double quote: "
string delimited by double quotes with single quote: ' and double quote: "</root>
https://xsltfiddle.liberty-development.net/6r5Gh2U
Upvotes: 1