[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Generating JSP/JSTL

Subject: Re: Generating JSP/JSTL
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Wed, 25 Apr 2007 11:53:24 +0200
Re:  Generating JSP/JSTL
Michael Kay wrote:
It's not possible with pure XSLT to generate XML that isn't
namespace-well-formed (for example, XML that uses a namespace prefix that
isn't declared). Does JSP/JSTL really require that?

Your best bet for achieving this output is to do some non-XSLT
post-processing of the XSLT result tree, for example generate the element
names as c_choose and then post-process to convert that to c:choose. You
could do that easily enough by sending the transformation output to a
SAXResult.

I don't fully agree with you here. I'm not sure what "pure" XSLT is about, but instructions like xsl:character-map are part of the core (pure?) XSLT language and can help us in making invalid output. Of course, it is the last thing you should do: create invalid XML and it is not going to help you application in becoming more understandable or even maintainable, but it is very well possible (but not trivial).


Here's a go at creating output the way the OP wanted it (though you loose on the indentation):

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:c="http://java.sun.com/jsp/jstl/core"
   xmlns:f = "http://functions"
   exclude-result-prefixes="#all"
   version="2.0">

<xsl:output method="xml" omit-xml-declaration="yes" use-character-maps="non-wellformed"/>

   <xsl:character-map name="non-wellformed">
       <xsl:output-character character="&#xE000;" string="&lt;"/>
       <xsl:output-character character="&#xE001;" string=">"/>
   </xsl:character-map>

<xsl:template match="/">
<ul>
<xsl:sequence select="f:create-non-wellformed-element('c:choose', 'foo')"></xsl:sequence>
</ul>
</xsl:template>


<xsl:function name="f:create-non-wellformed-element">
<xsl:param name="element-name" />
<xsl:param name="content" />
<xsl:value-of select="'&#xE000;', $element-name, '&#xE001;'" separator=""/>
<xsl:copy-of select="$content" />
<xsl:value-of select="'&#xE000;', '/', $element-name, '&#xE001;'" separator=""/>
</xsl:function> </xsl:stylesheet>



Which will produce the following output without producing any error:


<ul><c:choose>foo</c:choose></ul>


Still, when using JSTL and JSP, this is not going to help you, because JSTL requires the namespace to be bound and the XML to be legal. I'd be very interested to know why the OP wants a type of XML that is not going to work anyway... Nevertheless, in the words of someone whose name I forgot: "It *can* be done with XSLT".


Cheers,
-- Abel Braaksma

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.