Re: [xsl] Apostrification

Subject: Re: [xsl] Apostrification
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 5 Apr 2001 13:35:11 +0100
Hi Richard,

> How do I put an aprotophy in this string...
> <xsl:value-of select="concat('[@name = &apos;',@name,'&apos;]')"/>
> I think you can see what I'm trying to produce which is som
> debugging message that generates and X-Path to the problem

XSLT processors never see anything to do with what entities are used
where within XML. So as far as the XSLT processor is concerned, the
above attribute value is:

  concat('[@name = '',@name,'']')

This isn't a valid XPath. You need to change this string to be
something that the XSLT processor can parse as an XPath. Unfortunately,
there's no way to escape quotes in XPath. Fortunately, though you can
use both " and ' to delimit strings in XPath, so you can use:

  concat("[@name = '",@name,"']")


So, given this XPath, you have to then convert it to an attribute
value that an XML parser can accept. To make it well formed XML, if
you use "s to delimit the value of an attribute then you have escape
any "s with the XML entity &quot; to give:

  <xsl:value-of select="concat(&quot;[@name = '&quot;,
                                      @name,&quot;']&quot;)" />

Alternatively, you could use 's around the attribute value, in which
case you'd have to escape the 's in the XPath with &apos; to give:

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

Or you could escape both with just the same effect:

  <xsl:value-of select="concat(&quot;[@name = &apos;&quot;,
                                      @name,&quot;&apos;]&quot;)" />

And go mad and do the same thing for spaces:

  <xsl:value-of select="concat(&quot;[@name&#20;=&#20;&apos;&quot;,
                                      @name,&quot;&apos;]&quot;)" />

and so on, replacing all the characters with their equivalent
entities.  It matters not a jot to the XSLT processor - it will always
receive the same string, and try to interpret it as an XPath.

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread