Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
662 views
in Technique[技术] by (71.8m points)

xslt - xml, html or xhtml in <xsl:output>: Which is the better choice?

For historic reasons we have a mixture of

<xsl:output method="xml">

and

<xsl:output method="html">

and

<xsl:output method="xhtml">

inside an include-hierarchy of XSL files. Now we want to refactor so all XSL files use the same output method.

In the end we want to produce XHTML-output so I suppose the latter would be the best choice.

But what are the differences between those three output-methods and which would you use for what kind of solution?

Edit: I'm using XSLT 2.0

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

HTML will serialize as HTML, so the output may not be well-formed XML. If you are only sending to browsers and don't care about being able to parse as XML then that may work for you.

XML will serialize as XML, so the output will be well-formed, but you may run into some issues with browsers using the output. Small things, like self closing <script /> and <div /> elements. In order to avoid that issue you would have to play games, like adding comments inside of the element (e.g. <script src="someJSFile.js"><!--don't close my script tag --></script>)

If you have an XSLT 2.0 engine and want well formed HTML output without the headache of worrying about how some elements are serialized, then use XHTML.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...