Rendering XML in readable format in HTML

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?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
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

pbarry30Author Commented:
How to I replace say &lt; with <br/>&lt; in XSLT?
Geert BormansInformation ArchitectCommented:
For that you need a recursive function
here is an example

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="" 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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.