Proper URL Syntax in XSL-FO
February 26th, 2008 | by ndunn@webucator.com |I recently had a former XSL-FO student tell me she was having problems with graphics rendering in FOP version .094 when using relative paths. Unfortunately, I wasn’t able to help her figure out why not. She seemed to have the syntax correct. She used the following syntax, which is right out of our XSL-FO manual used in our XSL Classes.
<fo:external-graphic height="238px" width="340px"
src="url('Images/beatles.jpg')"/>
So, I went to the XSL spec and found this example:
<fo:external-graphic src="'url(TH0317A.jpg)'"/>
That threw me. Why single quotes around the whole string? So I emailed the editors of the spec asking if that code is correct and suggesting that it would be better to write it this way:
<fo:external-graphic src="url('TH0317A.jpg')"/>
or this way:
<fo:external-graphic src="url(TH0317A.jpg)"/>
I was impressed that they responded pretty quickly:
This is, admittedly, a bit of esoteric (full reply).
Under Property datatypes at http://www.w3.org/TR/xsl/#datatype
the <uri-specification> datatype is described. This definition was basically inherited from CSS. It says that the value is “A sequence of characters…” in which the quotes inside the parentheses are optional. So, despite the fact that url(…) might look like a function call, it is not–it just a string that happens to contain parentheses, and technically strings in the XSL expression language must be enclosed in quotes.
So in fact the form shown in the XSL spec is correct, and the other two shown above are not.However, many implementations do not enforce the need for quotes around the “url(…)” string [and I, for one, don’t blame them], so in practice, all three forms shown above will work.
I do understand that url() is not a function. But I don’t believe that’s an issue. As I understand it, in CSS a URI datatype is a subset of the string datatype. However, in FO, attribute values are often strings and there is no need to put extra single quotes around them.
It seems to me that the value of the src attribute below is a proper URI.
<fo:external-graphic src=”url(’TH0317A.jpg’)”/>
I checked out the CSS documentation (http://www.w3.org/TR/CSS21/syndata.html#uri) and it shows this example:
body { background: url("http://www.example.com/pinkish.png") }
That seems to me to use the same syntax as the src attribute above.
To agree with the code shown at http://www.w3.org/TR/xsl/#d0e9795, it would have to be:
body { background: "url(http://www.example.com/pinkish.png)" }
And that just doesn’t seem right to me. But I couldn’t find any documentation either way.
This is apparently completely academic as all the tools seem to allow for “my” syntax and the syntax used in the XSL spec.
You must be logged in to post a comment.