Subject: [xsl] How to retrieve Value of global parameter by matching ID. From: "Todeush, Serhiy" <Serhiy.Todeush@xxxxxxx> Date: Fri, 6 Sep 2002 10:26:00 +0100 |
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? Thank you for your help, Serhiy XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] [ANN] XSLT debugger (Sablotro, Petr Cimprich | Thread | [xsl] template's match-set ? (featu, Robert Koberg |
RE: [xsl] How to pass variable from, Khan, Amir | Date | [xsl] Performance optimization and , Lewden Romain |
Month |