For my output HTML file, I have to produce a div
element with an id
attribute, but the value of the attribute shouldn't stand in quotes, just like in this example: <div id=myID>...</div>
. Everything what I want to have, works perfectly when I use quotes, like here: <div class="myClass" id="{$myIdVariable}">...</div>
. Is it possible to tell Oxygen or Saxon to ignore such cases? But at the end I'm using the java javax.xml.transform
package, where I'm not aware of, if I can tell my classes I use to ignore things like that. I would be very glad, if someone has a good solution for this problem, or even could tell me, that this is not possible by using XSLT...
XSLT - HTML id attribute without quotes
Asked
Active
Viewed 460 times
1
-
@MartinHonnen: I believe the problem is that OP means *quotes*, not *parenthesis*.
– kjhughes
Oct 10 '17 at 21:33
-
The relevant W3C specification (XSLT 3.0 serialization) allows this attribute format but does not require it: "In those cases where they have no important effect on the content of the serialized result, details of the output methods defined by this specification are left unspecified and are regarded as implementation-dependent. Whether a serializer uses apostrophes or quotation marks to delimit attribute values in the XML output method is an example of such a detail." It would help to know WHY you care about such details.
– Michael Kay
Oct 12 '17 at 16:16
1 Answers
0
I believe your title should read without quotes, ""
, not without parenthesis, ()
.
No, XSLT is not going to help you create XML that's not well-formed. (You could stand on your head and output text rather than XML to achieve such a effect, but don't do that.) Attribute values must have single, '
, or double quote, "
, delimiters for the markup to be XML. Even the HTML output option is not going to serialize attribute values without quote delimiters.
In comments, @Ole asks:
In principle you are right, but I thought that in HTML5, also attributes without quotes are allowed?
Yes, in HTML5, unquoted attribute values are allowed, but you'll be better off using the single-quoted and double-quoted attribute value syntaxes that are also supported in HTML5, especially if you want to be able to leverage XML tools.
kjhughes
- 106,133
- 27
- 181
- 240
-
In principle you are right, but I thought that in HTML5, also attributes without quotes are allowed? I've solved this now, by parsing the XSLT output to remove the id quotes.
– Ole
Oct 11 '17 at 11:15
-
@MartinHonnen: I believe the problem is that OP means *quotes*, not *parenthesis*. – kjhughes Oct 10 '17 at 21:33
-
The relevant W3C specification (XSLT 3.0 serialization) allows this attribute format but does not require it: "In those cases where they have no important effect on the content of the serialized result, details of the output methods defined by this specification are left unspecified and are regarded as implementation-dependent. Whether a serializer uses apostrophes or quotation marks to delimit attribute values in the XML output method is an example of such a detail." It would help to know WHY you care about such details. – Michael Kay Oct 12 '17 at 16:16
1 Answers
I believe your title should read without quotes, ""
, not without parenthesis, ()
.
No, XSLT is not going to help you create XML that's not well-formed. (You could stand on your head and output text rather than XML to achieve such a effect, but don't do that.) Attribute values must have single, '
, or double quote, "
, delimiters for the markup to be XML. Even the HTML output option is not going to serialize attribute values without quote delimiters.
In comments, @Ole asks:
In principle you are right, but I thought that in HTML5, also attributes without quotes are allowed?
Yes, in HTML5, unquoted attribute values are allowed, but you'll be better off using the single-quoted and double-quoted attribute value syntaxes that are also supported in HTML5, especially if you want to be able to leverage XML tools.

- 106,133
- 27
- 181
- 240
-
In principle you are right, but I thought that in HTML5, also attributes without quotes are allowed? I've solved this now, by parsing the XSLT output to remove the id quotes. – Ole Oct 11 '17 at 11:15