Connecting Tech Pros Worldwide Forums | Help | Site Map

XSL Attribute Test

Newbie
 
Join Date: Sep 2009
Posts: 18
#1: Sep 14 '09
Q) How to check whether the value of an attribute is not null or if the lenght of characters in the value of an attribute is greater than 0?

Solution applied -->
s0SelectedSite is an attribute of a class or a column of a table.

Expand|Select|Wrap|Line Numbers
  1. <xsl:if test="string-length(@s0SelectedSite) &gt; '0'">
  2. <tr>
  3.   <td width="50%" bgcolor="#C0C0C0"><font size="2"><b>Selected Site:</b></font></td>
  4.   <td><font size="2">*<xsl:apply-templates select="DBE:Attribute   [@name='s0SelectedSite']"/></font></td>
  5. </tr> 
  6. </xsl:if>
In the above, the value of s0SelectedSite exists but still the lines are not getting printed.

For eg. It should display the following:-

Selected Site: Singapore
Please let me know if something is wrong.

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,664
#2: Sep 14 '09

re: XSL Attribute Test


Expand|Select|Wrap|Line Numbers
  1. <xsl:apply-templates select="DBE:Attribute[@name='s0SelectedSite']"/>
what is that supposed to do?
Newbie
 
Join Date: Sep 2009
Posts: 18
#3: Sep 14 '09

re: XSL Attribute Test


Its purpose is to display the the value of s0SelectedSite attribute which belong to a class/object.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,664
#4: Sep 14 '09

re: XSL Attribute Test


does it do what it is supposed to do?
Newbie
 
Join Date: Sep 2009
Posts: 18
#5: Sep 14 '09

re: XSL Attribute Test


Thanks to all....

0
I tried this way now --> It worked for me :

Expand|Select|Wrap|Line Numbers
  1. <xsl:choose>
  2.   <xsl:when test="string-length(DBE:Attribute[@name='s0SelectedSite']/node()) &gt; 0"> 
  3.     <table>
  4. ...<tr> 
  5.   <td width="50%" bgcolor="#C0C0C0"><font size="2"><b>Selected Site:</b></font></td> 
  6.   <td><font size="2">*<xsl:apply-templates select="DBE:Attribute   [@name='s0SelectedSite']"/></font></td> 
  7. </tr>
  8.     </table>
  9.   </xsl:when>
  10.   <xsl:otherwise>
  11.     <table>
  12. ...<tr> 
  13.   <td width="50%" bgcolor="#C0C0C0"><font size="2"><b>Selected Site:</b></font></td> 
  14.   <td><font size="2">*<xsl:apply-templates select="DBE:Attribute   [@name='s0SelectedSite']"/></font></td> 
  15. </tr>
  16.     </table>
  17.   </xsl:otherwise>
  18. </xsl:choose>
It works now.....i get the field empty incase of no value....incase of value i get the selected site value.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,664
#6: Sep 14 '09

re: XSL Attribute Test


Quote:

Originally Posted by prao2005 View Post

i get the field empty in case of no value....incase of value i get the selected site value.

that is correct behaviour. if you want to skip empty values, you have to test for them before.
Reply