We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Rendering XML in readable format in HTML

Medium Priority
Last Modified: 2013-11-19
Hi there,
we have CLOB objects in our database which contains XML data. We are reading this data and rendering our HTML pages with XSLT. Since the XML in this case is a data value, it comes encoded in our XML payload (&lt; &gt; instead of '<' and '>'). This is because we are using JAXB to handle the marshalling of our data objects and it encodes the data because it needs to produce well formed XML (at least that is what I am guessing)

So the question is - can I use XSLT to transform this encoded data so that I can put, at a minimum carriage returns before each tag?
What is happening currently is the HTML output is correct (<xsl:output method="html" indent="no"/>) but the XML is unreadable since we cannot enforce presentation - i.e. carriage returns and tabs

Any ideas?

Watch Question

Gertone (Geert Bormans)Information Architect
Top Expert 2006

Hi pbarry30,

you would get carriage returns in XSLT by having
(on two different lines)
you can also stuff that in a parameter and use it like that

<xsl:output method="html" indent="yes"/>
would already give you some indenting

unless what you are doing is having the XML escaped as pure text
(it seems from your question you do)

then the only thing you can do is stuff the XML wit <br /> for linebreaks and &nbsp; for spaces



How to I replace say &lt; with <br/>&lt; in XSLT?
Information Architect
Top Expert 2006
For that you need a recursive function
here is an example

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <xsl:call-template name="indentTags">
            <xsl:with-param name="argument" select="//yourElement"/>

    <xsl:template name="indentTags">
        <xsl:param name="argument"/>
            <xsl:when test="contains($argument, '&lt;')">
                <xsl:value-of select="substring-before($argument, '&lt;')"/>
                <br />
                <xsl:call-template name="indentTags">
                    <xsl:with-param name="argument" select="substring-after($argument, '&lt;')"/>
            <xsl:otherwise><xsl:value-of select="$argument"/></xsl:otherwise>

this stylesheet calls out for a named template that calls out for itself until all "&lt;" are processed
I assume the element //yourElement for replacing
you can call the template the first time  with the element that contains the pseudeoXML


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.