tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <>
Subject Re: dynamic xsl?
Date Sat, 09 Jun 2001 13:47:49 GMT
I'm resending this one - it seemed to disappear...

It sounds like you want to parameterize your XSLT.

e.g. using the xtags library

<xtags:style xml="helpDoc.xml" xsl="myStyleSheet.xsl">
    <xtags:param name="registration"><%= request.getParameter( "reg" )

would do the trick, passing in the value of the "reg" parameter into the
stylesheet as a parameter called "registration".

Then in your XSLT you'll need to declare the (global) parameter then refer
to it in XPath expressions as "$registration"...

    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="1.0"

    <xsl:param name="registration" />

    <xsl:tempate match="topics[topic = $registration]">
        <xsl:copy-of select="."/>

If all you need to do is extract a part of an XML document and output either
a fragment or bits of it, then you could just use the XTags library


<xtags:parse uri="helpDoc.xml"/>
<xtags:copyOf select="topics[topic=$reg]"/>

This would parse the XML document then evaluate the given XPath expression
to find the section you need and then copy the resulting node set to the JSP
output. Notice that in XTags you can use XPath variable notation ($reg)
inside XPath expressions to refer to 'variables'. The variable resolver
first looks in page, request, session and application scope attributes
first, if its not found it tries request parameters or init parameters.

So in XTags you can use XPath expressions to find and compare parts of XML
documents to Servlet attributes and parameters.

I hope this helps.


----- Original Message -----
From: "Richard A. Sand" <>
To: <>
Sent: Monday, June 04, 2001 8:50 AM
Subject: dynamic xsl?

> Hi all - please excuse me if this is a stupid question.  I've been playing
> around with the xsl tag libraries to make a simple help-system for a
> website.  I'm putting all of the site's help information into a single XML
> document, and then have an XSL document to take a single topic from the
> data and display it as HTML.  The problem I have is how to tell the XSL
> which help topic to display out of all of the topics contained in the XML
> file.  The topic requested by the user is part of the query string (i.e.
> /help/help.jsp?topic=registration).
> As a hack, my JSP page that invokes all of this reads the XML document,
> a DOM parser to find the topic requested and outputs only that XML
> inside an <xsl:apply> tag.  The XSL file then displays whichever topic was
> provided.  What I want to do is pass along the requested topic to the XSL
> page so that it can do something like:
> <xsl:tempate match="topics[topic = registration]">
> So, what I can't figure out is how to make the string "registration"
> the xsl document be dynamically generated, so that it can contain any
> keyword that I may have as a topic id.  Furthermore, if the topic id
> exist, I want to display the default topic (something that says "no help
> available" for example).
> From what I've read of Cocoon, I can make the XML document dynamic,
> simplifying my JSP page, but that's still not what I really need to do- I
> need to make the actual XSL page dynamic so that it can accept the topic
> name from the query string (via the JSP page).
> The help file is called "help.xml" and contains various topics divided
> topic tags such as:
> <topics>
>     <topic id="registration">
>     ...
>     </topic>
>     <topic id="login">
>     ...
>     </topic>
>     <topic id="forgottenpassword">
>     ...
>     </topic>
> </topics>
> Can someone tell me how to do this cleanly?
> Also, if anyone has seen a good thorough DTD for XML help systems like I'm
> writing I'd appreciate an example!  Mine is pretty basic and I'm sure this
> has been done before.
> Thanks!
> Best regards,
> Richard

View raw message