This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: creating XML in a servlet
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "Najmi, Jamal" <Jamal dot Najmi at Artesia dot com>
- Cc: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Sat, 6 Apr 2002 15:23:04 +0100
- Subject: Re: [xsl] creating XML in a servlet
- Organization: Jeni Tennison Consulting Ltd
- References: <0F966D8A9FE8D411A3450002B31A16D105B49D19@rckmail03.artesiatech.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Jamal,
> I want to know if it is possible to create chunks of XML based on
> certain parameters that a servlet receives from a form submitted by
> a web client.
In principle, yes. This is possible in Cocoon, for example, provided
that you configure it correctly.
> For example if form parameter name = 'title', and value of this
> parameter is 'Football', then ask XSL to create the following chunk
> of XML:
>
> <title>Football</title>
In XSLT, the names of the parameters that a stylesheet uses must be
hardcoded into the stylesheet. So you could declare the $title
parameter:
<xsl:param name="title" />
and then pass in the value 'Football' for that title parameter, and
do:
<title>
<xsl:value-of select="$title" />
</title>
But you can't vary the name of the parameter.
On the other hand, you could have a general parameter called
'parameter', for example:
<xsl:param name="parameter" />
and then use some delimiter in the value of that parameter to create
an element with a value. You can then pull the parameter value into a
'name' and 'value' using substring-before() and substring-after()
functions. Then create the element with a particular name using an
attribute value template in the name attribute of the xsl:element
instruction.
So for example if the $parameter parameter was set to 'title:Football'
then you could create the title element with:
<xsl:element name="{substring-before($parameter, ':')}">
<xsl:value-of select="substring-after($parameter, ':')" />
</xsl:element>
Or have separate parameters for the name and value of the element.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list