• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Namespaces are winding me up!

 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think there is an exclude-result-prefixes attribute you can set in the xsl:stylesheet tag that will do what you want.
I have not used this so YMMV
Bill
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Frank, I tried to use CDATA sections in XML also, and it seems close to what you want. I added comments and PIs to your XML to test:

and
<xsl:value-of select="content" disable-output-escaping="yes"/>
copies everything. Unless you need more fine-grained processing...
[ October 26, 2002: Message edited by: Mapraputa Is ]
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic