View Single Post
  #2 (permalink)  
Old June 6th, 2006, 09:03 AM
mhkay's Avatar
mhkay mhkay is offline
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

Firstly, don't do this:

<xsl:variable name="unit">
<xsl:value-of select="Selling_UM_1"/>

when you could do this:

<xsl:variable name="unit" select="Selling_UM_1"/>

In the first case you are constructing a tree, which involves copying data and allocating memory. In the second case you are merely creating a reference to existing nodes without copying anything.

Secondly, what do you mean by "empty"? There's a difference between the element being absent, and the element being present but without any content. It might even be present with irrelevant content, e.g <Selling_UM_1> </Selling_UM_1>. For convenience, I'll assume that you test for emptyness by testing whether normalize-space(Selling_UM_1) is a zero-length string.

Your logic is then:

  <xsl:when test="normalize-space($unit)">
    <a href="whatever"/>

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote