Re: [xslt] string literal with single-quote inside won't parse

Viktor Štujber wrote:
> This is interesting... could you point me to the part of the spec that
> describes the rules for constructing literals this way?

It’s got nothing (well, little) to do with XSLT; it is a result of the
XML syntax rules.

An attribute value must be bounded by " or '.  It may not contain its
bounding characters.  However, entity references may be used with an
attribute value:

<anxmlelement anattribute="a value with &quot;quotation marks&quot;"
  anotherattribute='a value with &apos;apostrophes&apos;'/>

XSLT 1.0 requires string literals to be delimited with " or ', and does
not provide an escape mechanism for those marks to be included.

'a string with "quotation marks"'
"a string with 'apostrophes'"

When a string literal needs to go in an attribute value, the rules must
be combined:

  select="'a string with &quot;quotation marks&quot;'"/>
  select='"a string with &apos;apostrophes&apos;"'/>

If you need both quotation marks and apostrophes in a string, you must
use concat().

concat('a string with "quotes" ', "and 'apostrophes'")

  select="concat('a string with &quot;quotes&quot; ',
                 &quot;and 'apostrophes'&quot;)"/>

Chris Maden, text nerd  <URL: >
“If Buzz Aldrin really went to the moon, why is he so afraid to
 show his real long form birth certificate?” —the Internet
GnuPG Fingerprint: C6E4 E2A9 C9F8 71AC 9724 CAA3 19F8 6677 0077 C319

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]