0

I need help with my XSLT.

I have an XML with encoded HTML tags with a tag:

input code

Using XmlSpy (Altova) this DOES work:

'<xsl:value-of select="de" disable-output-escaping="yes"/>'

which returns html tags within the data tag.

But executing this XSL on SAXON does not work. The XSL is executed and returns output, but the output-escaping seems to be ignored.

Any ideas?

  • How do you run Saxon exactly? Show us your command line or your Java/C#/etc. code. It will also help if you post the code as readable and copyable text and not as only as images. – Martin Honnen Sep 25 '20 at 16:47
  • 1
    For instance, at https://xsltfiddle.liberty-development.net/bEzkTdk you can see that e.g. Saxon 9.8 HE supports `disable-output-escaping="yes"`. You will really need to show us more details on how you use Saxon when you say disable-output-escaping is ignored. Make sure Saxon is in charge of serializing the XSLT result, don't expect a tree/node destination to contain the nodes. `disable-output-escaping` happens only during serialization. – Martin Honnen Sep 25 '20 at 17:00
  • As an alternative, to not depend on serialization, don't forget that there is an HTML parser implementation https://github.com/davidcarlisle/web-xslt/blob/master/htmlparse/htmlparse.xsl in pure XSLT 2 you can use and import and then you can parse the contents of the `de` elements into nodes you can copy through to the output, even an output tree: https://xsltfiddle.liberty-development.net/bEzkTdk/1 – Martin Honnen Sep 26 '20 at 19:51
  • @MartinHonnen: Thx for this brilliant hint - that parser helps me a lot, it is exactly what I was looking for! – Martin Schmidt Sep 28 '20 at 13:25

1 Answers1

1

The key thing to remember is that disable-output-escaping is an instruction to the serializer, and it has no effect unless the XSLT processor is serializing the output. The most common reason for it "not working" is that the transformation output is going to a destination other than the serializer (for example, a DOM tree). So we need to know how you are running the transformation.

Also related to this, there have been changes to the spec regarding what happens if you use disable-output-escaping while writing to a temporary tree (that is, to a variable).

Processors are allowed to ignore disable-output-escaping entirely, but Saxon doesn't do that, except of course when the output isn't serialized. (That's because "escaping" is a serialization thing, and if you're not serializing, then you're not escaping anything, so there is nothing to disable).

Michael Kay
  • 156,231
  • 11
  • 92
  • 164