ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Frank Carver <fr...@efsol.com>
Subject Namespace problems using style task to generate JSP
Date Thu, 24 Oct 2002 17:43:32 GMT
Hi,

I have a project which uses XSLT under the control of the Ant "style" task to
transform simple XML definitions of web pages to more complex HTML documents. For
static HTML pages this is working fine, For JSP pages this is only OK until I start
trying to use custom tags or JSTL.

A few months ago, when I last setup a new project doing this sort of thing, I guess
I was using a different parser and/or XSLT engine (it's hard to tell, exactly, as I
don't work there anymore). For this project I am using Ant version 1.5 and J2SE
version 1.4.1.

The problems I am encountering centre around namespaces. In this case "app" for my
own custom tags, "c" for JSTL core tags, and "x" for JSTL XML tags. What I ideally
want is for the styling process to just pass these through entirely unchanged: if
some page content says "<c:out value='ugh'/>" that's what I want to appear in my
JSP. I don't want any of the enclosing elements to sprout namespace declarations,
and I don't want to have to put long, complicated namespace declarations in my
"simple" page definitions.

If you think you can come up with a solution for this, here's an example for you to
try:

An example source page "ugh.xml", to be transformed to "ugh.jsp":
--------------------------------------------------------------------------------
<?xml version="1.0"?>
<page title="test">
 <content>
 Your <i>browser</i> is: <c:out value="${header['User-Agent']}"/>
 </content>
</page>
--------------------------------------------------------------------------------

A simplified stylesheet "page.xsl" to process it:
--------------------------------------------------------------------------------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="8859-1"/>
<xsl:template match="page">
 <xsl:text disable-output-escaping="yes"><![CDATA[
 <%@ page language="java" session="true" %>
 <%@ page import="java.io.*" %>
 <%@ page import="java.util.*" %>
 <%@ taglib prefix="app" uri="http://www.efsol.com/taglibs/example/custom" %>
 <%@ taglib prefix='c' uri='http://java.sun.com/jstl/core' %>
 <%@ taglib prefix='x' uri='http://java.sun.com/jstl/xml' %>
 ]]></xsl:text>
 <html><head><title><xsl:value-of select="title"/></title></head>
 <body>
  <h2><xsl:value-of select="title"/></h2>
  <xsl:apply-templates select="content/node()"/>
 </body></html>
</xsl:template> 

<xsl:template match="@*|node()|processing-instruction()|comment()">
 <xsl:copy>
  <xsl:apply-templates
   select="@*|node()|processing-instruction()|comment()"/>
 </xsl:copy>
</xsl:template>
</xsl:stylesheet>
--------------------------------------------------------------------------------

This is all called from the following target:
--------------------------------------------------------------------------------
<target name="style" depends="filter" if="exists.style">
  <style basedir="${temp}/style" style="${temp}/style/page.xsl" 
    destdir="${temp}" extension=".jsp">
    <include name="**/*.xml"/>
  </style>
</target>
--------------------------------------------------------------------------------


What I would like to see in the output is something like:
--------------------------------------------------------------------------------
<%@ page language="java" session="true" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ taglib prefix="app" uri="http://www.efsol.com/taglibs/example/custom" %>
<%@ taglib prefix='c' uri='http://java.sun.com/jstl/core' %>
<%@ taglib prefix='x' uri='http://java.sun.com/jstl/xml' %>
<html><head><title>test</title></head>
<body>
 <h2>test</h2>Your <i>browser</i> is: <c:out value="${header['User-Agent']}"/>
</body></html>
--------------------------------------------------------------------------------

Note that this is a fairly minimal valid JSP, with no extraneous namespace 
malarkey.

When i try the examples above, the XSLT processor refuses to load the
file "ugh.xml", complaining about the undeclared namespace.  If I add
namespace declaration(s) to the file "ugh.xml" (which I really don;t
want to do, as the whole point is to make the input files as simple as
possible) they end up plastered all over the output file.

Any suggestions ? Many thanks in advance. 

-- 
Frank Carver      frank@efsol.com         http://www.efsol.com/


--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message