Search code examples
htmlxmlxsltsaxonoxygenxml

XSLT - HTML id attribute without quotes <div id=myId>


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...


Solution

  • 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.