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

How to retrieve Value of global parameter by matching

Subject: 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
xsl value of parameter
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

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.