xsl-list
[Top] [All Lists]

Re: [xsl] Generating JSP/JSTL

2007-04-25 02:55:42
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



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--