Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
724 views
in Technique[技术] by (71.8m points)

xpath - how to escape single quote in xslt substring function

I tried to substring data with single quote in XSLT:

String : DataFromXML:'12345'

expected Result: 12345

<xsl:value-of select="substring-after('$datafromxml','DataFromXML:')"/>

Result: '12345'

i tried below code

<xsl:value-of select="substring-after('$datafromxml','DataFromXML:&#39;')"/>

<xsl:value-of select="substring-after('$datafromxml','DataFromXML:&apos;')"/>

<xsl:value-of select="substring-after('$datafromxml','DataFromXML:'')"/>

Error:

String literal was not closed 'DataFromXML:'--->'<---
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The general rules for escaping are:

In 1.0:

  • if you want the attribute delimiter in a string literal, use the XML escape form &quot; or &apos;
  • if you want the string delimiter in a string literal, you're hosed

In 2.0:

  • if you want the attribute delimiter in a string literal, use the XML escape form &quot; or &apos;
  • if you want the string delimiter in a string literal, double it (for example, 'I can''t')

The use of a variable $quot or $apos as shown by Vitaliy can make the code much clearer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...