7

My file base.css contains:

ol > li { color: red; }

I try to read it and render it into my HTML output using XSLT 2.0 unparsed-text (Saxon 9.1.0.2J) like this :

<style>
  <xsl:sequence select="unparsed-text(fn:iri-to-uri($CSS-BASE-FILE))"/>
</style>

However, the unparsed-text() function is converting the '>' to '&gt;' in the HTML, like this:

<style>
ol &gt; li { color: red; }
</style>

...Which doesn't behave as "ol > li" does.

How can I use XSLT to render the '>' character into my element? I've tried using replace(..., '&gt;', '>'), but that still renders '&gt;' into the HTML.

Alternatively, is there another way I can specify the CSS child selector without having to embed a literal '>' character into my HTML?

3
  • 1
    I think the problem is xsl:sequence. Why do you want to render the value of the unparsed text as a sequence instead of a literal string? Commented Nov 21, 2013 at 0:53
  • Using xxl:value yields the same result. Ah, but your comment leads me to the doorstep of disable-output-escaping, documented at saxonica.com. Commented Nov 21, 2013 at 6:07
  • The magic I needed is <xsl:value-of select="unparsed-text(fn:iri-to-uri($CSS-BASE-FILE))" disable-output-escaping="yes"/>. Commented Nov 21, 2013 at 6:41

1 Answer 1

2

Are you using output method XML, XHTML, or HTML?

The (3.0) specification says this:

The HTML output method MUST NOT perform escaping for any text node descendant, nor for any attribute of an element node descendant, of a script or style element.

So my suspicion is that you are not using the HTML output method.

Sign up to request clarification or add additional context in comments.

4 Comments

Hi, Mike. I'm using method="xhtml".
That explains it then. The XHTML output method generally follows the XML rules except for a few special situations where it does things differently. Generally I'm not sure there's much point generating XHTML for the browser: it understands HTML better, and if you have a need for an XML representation then you can generate that alongside the HTML.
So, Mike, to be clear on what you're saying: if I use <xsl:output method='html'>, then I won't need to use the disable-output-escaping attribute on the <xsl:value of> element (which does seem to work fine for me). Is that correct? Thank you.
I checked the W3C 3.0 spec, I didn't check the Saxon 9.1 implementation, but in principle yes, with method="html" it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.