472,146 Members | 1,288 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

XSL Attribute Test

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.
Sep 14 '09 #1
5 3425
Dormilich
8,658 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. <xsl:apply-templates select="DBE:Attribute[@name='s0SelectedSite']"/>
what is that supposed to do?
Sep 14 '09 #2
Its purpose is to display the the value of s0SelectedSite attribute which belong to a class/object.
Sep 14 '09 #3
Dormilich
8,658 Expert Mod 8TB
does it do what it is supposed to do?
Sep 14 '09 #4
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.
Sep 14 '09 #5
Dormilich
8,658 Expert Mod 8TB
@prao2005
that is correct behaviour. if you want to skip empty values, you have to test for them before.
Sep 14 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Patrick | last post: by
1 post views Thread by arnold | last post: by
3 posts views Thread by 7stud | last post: by
2 posts views Thread by =?Utf-8?B?dXJrZWM=?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.