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 12:28:00 PM
Hi Chris,



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 (why not, it's all xml anyway). You 
can then do it the 'xslt way' by defining templates. You code can become 
this:



<xsl:param name="key-settings">
   <setting name="MASTERCATALOGNAME" value="myvalue" />
   <setting name="PRODUCTID" value="myprodid" />
   ....
</xsl:param>

<xsl:template match="/" >



 <DataService>
    <Identity>
  [...]
    </Identity>
    <Transaction>
       <Command type="Query">
          <MasterCatalogRecord etype="Entity">
              <ExternalKeys>
                  <xsl:apply-template select="$key-settings/setting" />
              </ExternalKeys>
      [...]
    </Transaction>
 </DataService>

</xsl:template>



<xsl:template match="setting">
   <Key name="{@name}" type="string">
      <xsl:value-of select="@value" />
   </Key>
</xsl:template>





That's all there is too it. There is no need to add any xsl:if anymore, 
as the processor will do the thinking for you. If you don't want to 
chain the name of the Key to the name of the Setting, you can choose to 
add an external source that contains a lookup table (also in XML) with 
all your paramname/keyname mappings. You can get this resource with 
doc() or document() function.



If you use XSLT 1, you must use the node-set() extension function.



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