[xsl] making html output for application pages

Subject: [xsl] making html output for application pages
From: Bernie Bernstein <bernard@xxxxxxxxxxxxx>
Date: Fri, 19 Apr 2002 17:04:48 -0400
I'm currently in the process of converting some legacy .jsp files to output
xml which will then be processed by xslt to output the pages.

One of the reasons for this conversion is so that it will be easier to
translate the html versions of pages to different languages without messing
with the data processing side of things.

A few issues arise when doing this and I'll first give a little background.

For the jsp pages, we simply stripped out any html that was being output,
and changed it to just the data in xml form. Then we attached that output to
an xsl template which will take that data and output it as html.

This is working great using Resin as the engine for everything. In fact
there appears to be very little difference in output time between the jsp ->
html and the jsp -> xml -> xslt -> html versions.

Currently, all xml output is like this:

<top>
  <page>index</page>
  ... the rest of the data ...
</top>

where <page> contains a unique name for each page in the application.

When generating the pages, the xsl figures out the general layout of the
page and values of things like the page title, headers. This requires lots
of instances of:

<xsl:choose>
  <xsl:when test='/top/page = "index"'>
    <xsl:text>This is the index page</xsl:text>
  </xsl:when>
  <xsl:when test='/top/page = "somePage"'>
    <xsl:text>This is some other page</xsl:text>
  </xsl:when>
  ... and so on for about 30 pages ...
</xsl:choose>


This means that when someone is translating the "index" page, they need to
go through the entire document and find each of these choices and work on
the little bits of text inside.

I had thought it might be easier if I had some kind way of declaring all the
bits of text as variables at the top of the page, but I ran into a variable
scoping problem.

I may be thinking in the wrong paradigm, but I wanted some way to say
"setupIndex" where one chunk of code would set up a bunch of variables that
would all be used later on in the <top> template.

In other words, I wanted to have some way of saying in one place:

<xsl:choose>
  <xsl:when test='/top/page = "index"'>
    <xsl:call-template name='setupIndex' />
  </xsl:when>
  <xsl:when test='/top/page = "somePage"'>
    <xsl:call-template name='setupSomePage' />
  </xsl:when>
  ... and so on for about 30 pages ...
</xsl:choose>

Where these templates would declare variables, but as you know, the scope of
those variables would go away as soon as they left their context, so that
didn't work.

Instead I did the following which I'm still not happy with:

<xsl:variable name='pageName'>
 <xsl:choose>
  <xsl:when test='/top/page = "index"'>
    <xsl:text>This is the index page</xsl:text>
  </xsl:when>
  <xsl:when test='/top/page = "somePage"'>
    <xsl:text>This is some other page</xsl:text>
  </xsl:when>
  ... and so on for about 30 pages ...
 </xsl:choose>
</xsl:variable>

Which works, but seems non-xslt-like to be doing it like that. I'm wondering
if it might make more sense to have the xml data look like one of these
instead.

<top>
  <index>
     ... the page data ...
  </index>
</top>

or simply:

<index>
  .. the page data ...
</index>

Since we are controlling both ends of this, we are still flexible with out
the data is represented.

We are not flexible with the data itself of course. So, for example, we
won't be able to pass the page name to xslt since that is associated with
the html output, not the data, although in some cases, the page name might
be related to some of the data.


I appreciate any help.


Bernie



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread