prashant rao
prashant rao

Reputation:

How to check whether the value of an attribute is not null or if the length of characters in the value of an attribute is greater than 0

s0SelectedSite is an attribute of a class or a column of a table.

<xsl:if test="string-length(@s0SelectedSite) &gt; '0'">
<tr>
  <td width="50%" bgcolor="#C0C0C0"><font size="2"><b>Selected Site:</b></font></td>
  <td><font size="2">&#160;<xsl:apply-templates select="DBE:Attribute   [@name='s0SelectedSite']"/></font></td>
</tr> 
</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.

Upvotes: 0

Views: 13840

Answers (4)

Jarod83
Jarod83

Reputation: 1

Here is how i use it in a template. It matches every @dateEnd that's not empty.

<xsl:template match="@dateEnd[. != '']">
   ...
</xsl:template>

Upvotes: 0

prashant rao
prashant rao

Reputation:

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

<xsl:choose>
  <xsl:when test="string-length(DBE:Attribute[@name='s0SelectedSite']/node()) &gt; 0"> 
    <table>
...
    </table>
  </xsl:when>
  <xsl:otherwise>
    <table>
...
    </table>
  </xsl:otherwise>
</xsl:choose>

Upvotes: 0

Wiretap
Wiretap

Reputation: 781

I find this generally works for checking to see if a tag is populated

<xsl:if test="@s0SelectedSite !=''">

Could you provide a sample of the xml, as I use this all the time and am wondering if the xpath is the issue.

Upvotes: 2

Kobi
Kobi

Reputation: 138097

  1. Try <xsl:if test="string-length(@s0SelectedSite) &gt; 0"> (and not '0').
  2. Try <xsl:if test="@s0SelectedSite"> , see if it's working for you.

Upvotes: 1

Related Questions