1. Producing jsp from xslt
2. How to pass xml into a JSP page
3. JSP in XSL
4. XSLT Saxon Transformation in JSP pages


Producing jsp from xslt

Mike Brown

> Hi.  I'm trying to transform XML into an HTML/JSP page.

Unfortunately, JSP is not HTML. When you rely on the XSLT processor to serialize the result tree in HTML syntax, it's going to make conservative decisions as to how to make abstract elements, attributes, and character data manifest as encoded text with embedded markup. The HTML it produces is intended to be processed by a conforming HTML user agent. A JSP engine is not such an agent.

The serializer does know that certain HTML attributes are subject to different kinds of formatting, but it has no way of knowing that instead of one of the standard types of attribute values, you want to insert a completely unescaped JSP tag.

> I've followed the suggestion at
> using:
> <xsl:attribute name="action" saxon:disable-output-escaping="yes"
>   <xsl:text
> </xsl:attribute>
> [...]
> This is what I get:
>   <form method="get" action="<%25=request.getRequestURI()%25>">
> And of course I'd like:
>   <form method="get" action="<%=request.getRequestURI()%>">

Ordinarily that method would work, but the "action" attribute of an HTML form element is one of those special attributes that is supposed to be a URI reference, so the serializer, thinking it is helping you produce a proper value, is turning "%" into "%25". This behavior is not required by the XSLT spec except for non-ASCII characters, and IMHO it should not be happening at all (e.g., what if you already had properly escaped such characters in your URI?)

So I would call this a bug in Saxon. saxon:disable-output-escaping="yes" should, IMHO, disable *all* escaping.

> <xsl:attribute name="action">
>   <xsl:text
> </xsl:attribute>

That method would definitely not work because xsl:attribute discards the text nodes that were created in its content and only uses their encapsulated text. Escaping only happens at serialization time. The d-o-e flag indicates you'd prefer the serializer to not escape a text node's encapsulated text upon output, but that only applies to the serialization of the text node; it doesn't change the node's encapsulated text at all.


How to pass xml into a JSP page

Steve Muench

Passing a string to new InputSource() expects
the string to represent an URL.

What you want to do is:


 String New_val = request.getParameter("packet");
 ByteArrayInputStream bais = 
        new ByteArrayInputStream(New_val.getBytes());
 InputSource is = new InputSource(bais);


This will feed the XML document in a string as an




Gareth Sylvester-Bradley

>  there is apparently an XML representation of JSP pages that
> uses proper XML tags.

The sun site describes the newer XML format for JSP.

http://www.abc2xml.com/wrox/chapters/2858_Chapter10/28581002.asp is a chapter of a Wrox book describing both old and new syntax.

Both of these were on the first page of a Google search for "JSP XML syntax".


XSLT Saxon Transformation in JSP pages

Vincent Blondel

Something like this ...

<%@ page contentType="text/html"

      java.io.*" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     <html xmlns="http://www.w3.org/1999/xhtml"; lang="en" xml:lang="en">


StreamSource xml = new StreamSource(new File("c:/temp/hello.xml"));
StreamSource xsl = new StreamSource(new File("c:/temp/hello.xsl"));

StreamResult result = new StreamResult(out);

TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(xsl);

transformer.transform(xml, result);

and, great, it works .

Robert Koberg added :

You will probably want to create a Templates object to cache and create you Transformer off of that. You will get better performance. Also, before you write your own taglib, you might want to check out: apache If you don't like it, at least you can use it as a starting point.