Subject: Re: [xsl] How to retrieve Value of global parameter by matching ID. From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Fri, 06 Sep 2002 12:51:34 -0400 |
<parameters> <param name="client.name">Jhon Smith</param> <param name="client.address">XX Somestreet, Sometown</param> <param name="client.postcode">NNN NNN</param> </parameters>
<xsl:template match="fld"> <xsl:variable name="parameter" select="$parameters[@name = current()/@id]"/> <xsl:value-of select="$parameter"/> <xsl:if test="not($parameter)"> <xsl:text>The field named [" </xsl:text> <xsl:value-of select="@id"/> <xsl:text>"] is not found!</xsl:text> </xsl:if> </xsl:template>
I hope that helps, Wendell
Hello,
I recently started to work with XSLT and have this question about global parameters.
I work with web-based application, which produces PDF documents, using FO-XML. The documents include some dynamic fields. The values of those fields are coming from database and passed as global parameters from servlet into XML.
Snip of XML file: ======================================== <para> This is the value of Name filed: <fld id="client.name" /> This is the value of Address filed: <fld id="client.address" /> This is the value of PostCode filed: <fld id="client.postcode" /> </para> ========================================
Here is the associated XSL file:
======================================== <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" encoding="iso-8859-1"/>
<xsl:param name="client.name"/> <xsl:param name="client.address"/> <xsl:param name="client.postcode"/> .... .... <xsl:param name="producer.name"/> <xsl:param name="producer.addr1"/> ....
<xsl:template match="/"> <xsl:apply-templates/> </xsl:template>
<xsl:template match="fld"> <xsl:choose> <xsl:when test="@id='client.name'"> <xsl:value-of select="$client.name"/></xsl:when> <xsl:when test="@id='client.address'"> <xsl:value-of select="$client.address"/></xsl:when> <xsl:when test="@id='client.postcode'"> <xsl:value-of select="$client.postcode"/></xsl:when> .... .... <xsl:when test="@id='producer.name'"> <xsl:value-of select="$producer.name"/></xsl:when> <xsl:when test="@id='producer.address'"> <xsl:value-of select="$producer.address'"/></xsl:when> .... <xsl:otherwise> <xsl:text>The field named [" </xsl:text> <xsl:value-of select="@id"/> <xsl:text>"] is not found!</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:template>
</xsl:stylesheet> ==========================================
The result of transformation looks something like that:
======================================== This is the value of Name filed: Jhon Smith This is the value of Address filed: XX Somestreet, Sometown This is the value of PostCode filed: NNN NNN
======================================== Where Jhon Smith, XX Somestreet, Sometown, NNN NNN - are values of corresponding fields in database.
At the moment I have to add new [ <xsl:when test="@id='...'"> ...</xsl:when> ] entry for <fld> tag in XSL each time there is a filed with new ID to be added in the documents. There are already more than one hundred fields in the documents and the number is growing.
My question is: Is there a better way to design <fld> tag? In other words, is it possible to write some generic code, which will return value of global parameter by matching fld[@id] without need to update <fld> tag in XSL every time?
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] template's match-set ? (f, Wendell Piez | Thread | [xsl] Performance optimization and , Lewden Romain |
[xsl] complex sorting, Isaac Blaise | Date | Re: [xsl] template's match-set ? (f, Wendell Piez |
Month |