Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

xslt - XSL: Include some ASCII control chars when method="text"

I've got an XSL template that outputs text as opposed to XML. In this text, I need to include ASCII character 0x10 in certain position.

I understand this character is not allowed in an XML document, but I'm going to output text, so why am I not allowed to use it anyway?

I also understand it will not be possible to put this character literally into the template, neither within a CDATA section nor as &#16;. But why does on-the-fly generation not work either? I tried, for instance, to define a function that returns this char and used it as <xsl:value-of select="z:get_char(16)"/> but that produces an Invalid character exception either.

Is there a way?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Since the XSLT file is an XML file, you cannot include that character reference. I don't think you can do this in a pure XSLT solution.

The ASCII character HEX 10/DEC 16 is the Data Link Escape (DLE) control character.

The XML Spec only allows the three whitespace(tab, carriage return, line feed) control characters.

Legal characters are tab, carriage return, line feed, and the legal characters of Unicode and ISO/IEC 10646.

Everything else under 0x20 is not allowed.

Character Range 2 Char ::=
#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */

One option is to put a placeholder token value for that character in your output, and then use an external process to find/replace your token with the character.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...