Re: [xsl] single quotes instead of double

Subject: Re: [xsl] single quotes instead of double
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 21 Nov 2011 07:41:41 -0500
At 2011-11-21 11:44 +0000, Andrew Welch wrote:
On 21 November 2011 11:35, Szabo, Patrick (LNG-VIE)
<patrick.szabo@xxxxxxxxxxxxx> wrote:
> Hi,
> I'm currently working together with external developers and they sent me
> a stylesheet that has the following code in it:
> <xsl:when test="$mode = 'versionbranch'">
>         <xsl:value-of select='$documentid'/>
> </xsl:when>
> As you can see there are single quotes where normally at least i would
> write double quotes.
> I'm wondering if that could make any difference in any circumstances.

No but while it's technically legal it's inconsistent with the line
above, and with xslt style in general.

I disagree with making this generalization.

The general rule is - use double quotes.

It is purely a matter of convenience for the writer of the expression. And an XSLT processor can choose either quote to use as an attribute literal delimiter.

I feel *obliged* to use single quotes for an attribute in XSLT that uses the "url()" syntax in an XSL-FO stylesheet because of the allowed characters in a URI:

<external-graphic src='url("{$uri}")'/>

Because a single quote is allowed in a valid URI, double quotes inside the url() are necessary.

Of course I could have written the above as:

external-graphic src="url(&#34;{$uri}&#34;)"


external-graphic src="url(&#x22;{$uri}&#x22;)"

and used double quotes for the attribute delimiter, but I think this is harder to maintain down the road for someone reading the numeric character entities.

For someone reading XML, the attribute delimiter chosen should be irrelevant because it is, syntactically, irrelevant. So use whatever you want and don't bother imposing a style.

I find I simply use as the closing delimiter whichever quote I happened to type for the opening delimiter, which is not always a double-quote. Sure, it usually is, but since it doesn't have to be I don't force myself.

I hope this helps.

. . . . . . . . . . . Ken

Contact us for world-wide XML consulting and instructor-led training
Free 5-hour video lecture: XSLT/XPath 1.0 & 2.0
Crane Softwrights Ltd.  
G. Ken Holman                   mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Google+ profile:
Legal business disclaimers:

Current Thread