[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Including a JSP file in an XSL

Subject: Re: Including a JSP file in an XSL
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 13 Feb 2001 13:21:14 +0000
include jsp in xsl
Hi Lyndall,

> I'm trying to do pagination for printing HTML using XML/XSL
> transformations... A header and footer is required for each page.
> Using the <xsl:for-each > command, I have been able to get the
> header/footer thing happening, but as I have several pages, which
> all require the same header and footer, instead of copying the
> header/footer into each XSL, I would like to be able to reference
> separate jsp files. The header and footer are made up of html tables
> with text and images.

You might well be able to achieve what you're after using just XSLT.

For one thing, if you do:

  <xsl:copy-of select="document('header.xml')" />

then the contents of header.xml will be copied into the right place.
If header.xml is well-formed XHTML, then it should work fine.  But it
may well be that it isn't - that it has two top-level elements, for
example.

An alternative is an XML entity:

<!DOCTYPE xsl:stylesheet [
<!ENTITY header SYSTEM 'header.xml'>
]>
...
   &header;
...

But it sounds like you should put some XSLT templates creating the
header and footer that you want into a separate stylesheet that you
then import into all the stylesheets that use them.  For example:

--- header-and-footer.xsl ---
...
<xsl:template name="insert-header">
   <!-- loads of tables and so on -->
</xsl:template>
...
---

--- stylesheet.xsl ---
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="header-and-footer.xsl" />

...
   <xsl:call-template name="insert-header" />
...

</xsl:stylesheet>
---

> I have tried using <%@ include file="header.jsp" %> (which is
> rejected by the processor) and replacing the % with the relevant
> representation doesn't help either (not that I really expected it
> to!)

The XSLT processor has no way of recognising JSP instructions, so you
can't use them to automatically include things in your XSLT
stylesheet.  You need to use one of the methods above if that's what
you want.

If you want to have a stylesheet that includes JSP instructions in the
*output* (which can then be processed to include the relevant
information), then I think this is one of the very rare situations in
which disable-output-escaping is useful. The 'tags' you are creating
aren't proper XML, so you have to escape the less-than sign to
indicate that it isn't the start of an XML tag:

  &lt;%@ include file="header.jsp" %>

But that will be outputted with the escaped syntax as well, and
therefore not recognised by whatever JSP processor looks at the
output.  Instead, use:

  <xsl:text disable-output-escaping="yes">
     &lt;%@ include file="header.jsp" %>
  </xsl:text>

This will produce the JSP instruction in the output, which can then be
processed to include the header and footer.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.