Repository navigation
Conversation
serialize() always used slimdom's XMLSerializer, so method="html" produced self-closed <div/> elements, entity-escaped script/style content and no doctype, which browsers render incorrectly. The unnamed xsl:output declaration was also never applied to the default result document; only xsl:result-document with a format consulted the output definitions. - Add src/serialize.ts with serializers for the html, xhtml and text output methods (doctype, void elements, raw script/style content, minimized boolean attributes, content-type meta, namespace fixup). - Read method and include-content-type from xsl:output and xsl:result-document. - Apply the unnamed output definition to the #default result, and use it as the base for xsl:result-document without a format. - mkOutputDefinition only sets options that were specified, so definitions layer correctly. Multiple unnamed xsl:output declarations are now actually merged (the merge branch was dead code), later ones overriding earlier ones. - Match named output definitions by expanded QName and raise XTDE1460 for an unknown format. - Choose the html method by default when the document element is html in no namespace (XSLT 2.0 section 20). - Add test/serialize.spec.ts. Eleven tests of the W3C suite now pass (output-0111, 0113, 0154, 0172, result-document-0214, 0215, 0230, 0236, 0701, bug-0304, error-1460a). Fixes egh#13 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Moritz Stückler <moritz@bitbetter.de>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13.
What was wrong
serialize()always used slimdom'sXMLSerializer, somethod="html"produced<div/>, entity-escaped<script>/<style>content and no doctype. Browsers parse that as nested unclosed<div>s and the inline JavaScript breaks.xsl:outputdeclaration was never applied to the default result document at all:outputDefinitionswas only consulted byxsl:result-document format="...". So evenomit-xml-declaration="yes"had no effect on the main output (xjslt runprinted the XML declaration regardless).What this PR does
src/serialize.ts(new) – serializers for thehtml,xhtmlandtextoutput methods, following the XSLT/XQuery Serialization spec:html:<!DOCTYPE html>(or the doctype built fromdoctype-public/doctype-system), no XML declaration; void elements written as<br>with no end tag, other empty elements as<div></div>;script/stylecontent written raw; boolean attributes minimized (checked="checked"→checked);<not escaped in attribute values;<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">inserted intoheadunlessinclude-content-type="no"; processing instructions terminated with>. Elements in the XHTML namespace are treated as HTML elements, elements in other namespaces (SVG, MathML) are written as XML. Namespace declarations are emitted the same wayXMLSerializerwould.xhtml: XML syntax with the HTML conventions (<br />,<div></div>, content-type meta, doctype).text: the string value of the result tree.methodis declared and the document element ishtmlin no namespace, the html method is used, as XSLT 2.0 §20 requires.Output definitions
methodandinclude-content-typeare read fromxsl:outputandxsl:result-document.#defaultresult (applyDefaultOutputDefinition), andxsl:result-documentwithoutformatalso falls back to the unnamed definition, as the spec says.mkOutputDefinitiononly sets the options that were actually specified, so definitions can be layered without an unspecified option (e.g.standalone) clobbering a specified one. Several unnamedxsl:outputelements are now actually merged (the merge branch incompileOutputNodewas dead code:namewas never falsy), later ones overriding earlier ones per option.xsl:output name="my:f"andxsl:result-document format="other:f"match when both prefixes are bound to the same namespace. An unknownformatraisesXTDE1460instead of being silently ignored.The
xmlmethod is unchanged.🤖 Generated with Claude Code