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: The source page "ugh.xml", to be transformed to "ugh.jsp":
An simplified stylesheet "page.xsl" to process it:
What I would like to see in the output is something like:
Note that this is a minimal valid JSP, with no extraneous namespace malarkey. Any suggetsions ? Thanks in advance. [Map killed smiles so they wouldn't be ashamed of c:out tags] [ October 26, 2002: Message edited by: Mapraputa Is ]
Thanks Bill. I tried that, and there seem to be problems (or at leat misunderstandings on my part). The first problem is that you can only "exclude" prefixes which you have already specified, so I have to put large and unwieldy xmlns declarartions in all my "simple" page specifications, as well as putting the "exclude" in the stylesheet. The second problem is that however hard I try, I can't get it to exclude all the namespace declarations in the generated document. This has the unfortunate side effect that lots of ordinary HTML elements in the JSP get xmlns declarations added to them. I wouldn't really mind except that the JSP processor leaves them in place in the output HTML, which not only makes the generated pages bigger, but gives any casual "View Source" way too much information about how the page was generated. Given that XSLT is purely a transformation system, I can't believe that there is no way to just say "treat ns:tagname" as a single name, like the old XML parsers used to.
Thanks. The CDATA approach is what I've settled for in most cases. For the occasional page which might need further processing I'm living with the extra namspace declarations for the moment. I'm also toying with the idea of preprocessing my simple page definitions using something else to add in namespace declarations, and then postprocessing the generated JSP and HTML to remove them before deployment. Seems a lot of effort, though