Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Only output element when parameter value is not equal to blank (or null)

From: Abel Braaksma <abel.online@--------->
To:
Date: 2/1/2007 1:39:00 PM
Florent Georges wrote:
You can make your stylesheet miles simpler and shorter by

using a different approach. Instead of tons of parameters,

use something extensible, like an XML structure

    

  It simplifies the stylesheet, yes, but it is not always
what you want.  You can want to provide a lot of parameters,
settable from the command line interface of several
processors, without requiring intalling other piece of
software.  In this case, defining (even a lot of) parameters
taking only string values is what you want.

  Regards,



--drkm

  

One additional thought I left out is, to ease your development, to use 
tokenized parameters. But you are right, depending on your target 
system, and whether you can control how the xslt is called, you may and 
up with an unwieldy garden of parameters. We can't always have what we want.



But the way I look at it, seeing the OP's code, it looks awfully much 
like a hard maintainable piece of xslt. There are many ways to ease it, 
especially with the help of XSLT 2. And if you can't use XML or 
tokenized parameters, you can still keep all the logic around the huge 
amount of parameters together by using one additional variable (not 
parameter) that looks like my suggested param. The very least you will 
gain is: 20+ less xsl:if statements and much more readable/maintainable 
code.



Of course, modularizing your code, and how much time you want to spend 
on it, is all a matter of taste. Here's an upgraded example that 
illustrates my thoughts, leaving the OP's original parameters intact:



<xsl:param name="catalogName" />
<xsl:param name="productId" />

<xsl:variable name="key-settings">
  <setting name="MASTERCATALOGNAME" value="{$catalogName}" />
  <setting name="PRODUCTID" value="{$productId}" />
  ....
</xsl:variable>

<xsl:template match="/" >
.....

rest of the templates remain the same, see my earlier post on it, except 
for this one (see the slight change in the match):




<xsl:template match="setting[normalize-space(@value) != '']">
  <Key name="{@name}" type="string">
     <xsl:value-of select="@value" />
  </Key>
</xsl:template>


Cheers,
-- Abel Braaksma


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent