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: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Firstly, don't do this:

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

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:choose>
  <xsl:when test="normalize-space($unit)">
    <a href="whatever"/>
  </xsl:when>
  <xsl:otherwise>#xa0;</xsl:otherwise>
</xsl:choose>




Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote