tags:

views:

41

answers:

1

Given the following XML file:

<?xml version="1.0" encoding="UTF-8"?>
<doc>
     <head>
         <title>Introduction</title>
         <section>section</section>
         <channel>testing/test</channel>
     </head>
     <body>
         <h1>Heading</h1>
         <p>Lorem ipsum dolor sit amet.</p>
         <p>Donec sed enim.</p>
     </body>
</doc>

and the following JSTL fragment where the xml has been loaded into the variable 'file':

<x:parse var="xml" doc="${file}"/>
<x:out select="$xml//body"/>

I am hoping to get:

<h1>Heading</h1>
<p>Lorem ipsum dolor sit amet.</p>
<p>Donec sed enim.</p>

But am getting:

Heading Lorem ipsum dolor sit amet. Donec sed enim.

Notice, no tags. How would I go about getting JSTL to leave the tags in the result?

+1  A: 

x:out is very similar to xsl:value-of in that it will only select text nodes. Therefore if you want to preserve the XML structure then I would suggest using x:transform and writing a stylesheet that will use a xsl:copy-of to preserve tags. Another option is to write your own tag :-).