1

Say I have the following XML:

<root>
    <node attr="<b>hi</b>" />
    <node attr="<b>bye</b>" />
</root>

How can I get the XSLT 1.0 code to render the actual HTML in the attribute?

This doesn't work as it ouputs <b>hi</b>.

<xsl:value-of select="@attr" disable-output-escaping="yes"/>

Any ideas?

Clarification

I am using this on SharePoint 2010 in a DVWP WebPart. The WebPart will let me use XSLT to transform the XML returned of a list into HTML that is displayed on the browser. Right now the rendered output is <b>hi</b> instead of bolded text. I guess what I need to do is disable-output-escaping twice. The first time will get the <b>hi</b> and the second time it'll be rendered. Make sense?

5
  • 2
    "This doesn't work as it ouputs <b>hi</b>." What would you want it to output? -- P.S. That's not really what your XML looks like, is it? Because that would only generate an error. Commented May 21, 2015 at 19:26
  • I want it to render hi as bolded text. Right now the output has the literal <b>hi</b>. And yes, I know but I figured I'd leave it simple for the sake of brevity. Commented May 21, 2015 at 19:32
  • where are you running this that you expect the bold to be rendered? Good luck. Commented May 21, 2015 at 20:05
  • @shellter: I should have clarified. I'm sorry. Added details. Commented May 21, 2015 at 22:28
  • If the rendered output is <b>hi</b>, then the HTML result is not what you say it is. It is hard to tell exactly what is happening here, because your XML is obviously not what you show us, and the XSLT is partial. I suggest you post enough code (XML + XSLT) to enable us to reproduce the issue. Commented May 21, 2015 at 22:58

1 Answer 1

2

You are asking for something that is not. The result of an XSL transformation is a text document: it can be XML, HTML or plain text (in fact, XML and HTML are also types of plain text documents).

Bolded text as such exists only on the screen, after some application has rendered the text marked up as bold. In the case of an HTML markup, the application that does the rendering is a web browser.

If you want to see a rendered view of the HTMl resulting from your transformation, you need to insert a browser at the end of your processing chain. Some XSLT editors have a built-in web browser, allowing you to switch the view of the result between the "raw" result and a rendered view. But that has nothing to do with the XSL transformation itself.


Added in view of your clarification:

There are two things you should know about disable-output-escaping that may be relevant to your situation:

  1. An XSLT processor is not required to support disabling output escaping.

  2. An XSLT processor will only be able to disable output escaping if it controls how the result tree is output. This may not always be the case.

These are direct quotes from the XSLT 1.0 specification.

I am not sure how SharePoint works, but if - for example - the XSLT transformation passes its result directly to the browser as a DOM tree, instead of serializing it to "a sequence of bytes' (i.e. a file), then disable output escaping will have no effect.

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

3 Comments

I guess I should have clarified. I updated the question.
I'm not sure what the raw XML has but when I render using disable-output-escaping the output on the browser page is <b>hi</b> and not a bolded hi. The rendered HTML is &gt;b&lt;hi&gt;/b&lt;. I assume the raw XML has something like &amp;gt;b&amp;lt;hi&amp;gt;/b&amp;lt; which means the disable-output-escaping converts the &amp; to & and sends the output to the browser. Not sure it that makes sense.
@IMTheNachoMan "I'm not sure what the raw XML has" Use the identity transform template to find out.

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.