Escape single quote in xslt concat function

79,374

Solution 1

Use '?

<xsl:value-of select="concat('process[@Ref=&apos;',$ID,'&apos;]')"></xsl:value-of>

Edit: See Dimitre's answer for a better solution.

Solution 2

In XPath 1.0:

You can use the built-in entities &apos; and &quot;

In XSLT 1.0:

Alternatively, you can define your $Q and $APOS variables (put the content (the literal " or the literal ' character) in the body of the xsl:variable, not in the select attribute).

In XPath 2.x (this also means XSLT 2.x and XQuery 1.x)

Simply escape an apostrophe by entering two adjacent apostrophes, escape a quote by entering two adjacent quotes, as defined by the XPath 2.0 language

Solution 3

To expand on Dimitre's answer, you can use this solution in XSLT:

<xsl:variable name="apos">'</xsl:variable>
<xsl:value-of select="concat('process[@Ref=',$apos,$ID,$apos,']')"></xsl:value-of>

Solution 4

<xsl:value-of
select="concat('process[@Ref=&apos;',$ID,'&apos;]')"></xsl:value-of>

this doesn't work for me. My solution is:

<xsl:value-of select="concat(&quot;process[@Ref='&quot;,$oidConstant,&quot;'&quot;)"></xsl:value-of>
Share:
79,374
keshav84
Author by

keshav84

will tell later

Updated on July 16, 2022

Comments

  • keshav84
    keshav84 almost 2 years

    I want to output single quote around $ID variable in the below xsl:value-of xsl statment.

    <xsl:value-of select="concat('process[@Ref=',$ID,']')"></xsl:value-of>
    

    currently it prints

    process@Ref=87799989
    

    Please let me know how can i achieve this.

    Thanks in advance, Keshav