Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape single quote in xslt concat function

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

like image 809
keshav84 Avatar asked May 22 '10 07:05

keshav84


People also ask

How do you escape a single quote in XSLT?

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).

How do I concatenate in XSLT?

Concat function in XSLT helps to concatenate two strings into single strings. The function Concat() takes any arguments that are not the string is been converted to strings. The cardinality function passed over here in each argument should satisfy zero or one function() respectively.

How do I replace in XSLT?

XSLT replace is deterministic and does string manipulation that replaces a sequence of characters defined inside a string that matches an expression. In simple terms, it does string substitution in the specified place by replacing any substrings. Fn: replace function is not available in XSLT1.


2 Answers

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

like image 198
Dimitre Novatchev Avatar answered Sep 20 '22 10:09

Dimitre Novatchev


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> 
like image 35
Veloz Avatar answered Sep 17 '22 10:09

Veloz