tags:

views:

34

answers:

4

Hi there basically I need to find how many characters are in a variable using XSL

if characters($Title == 12) { execute code; }

Basically something like above obviously this is incorrect can any one help?

thanks in advance

A: 

string-length($varname) will tell you the length of a variable containing data that can be interpreted as a string.

Paul Butcher
Thank you very much for your help
NWhite
A: 

In XPath 1.0:

string-length($title) = 12

Take notice that diacritical marks also would be counted.

In XPath 2.0 you cuold use:

string-length(normalize-unicode($title)) = 12
Alejandro
A: 

basically I need to find how many characters are in a variable using XSL

if characters($Title == 12) { execute code; }

Use:

 <xsl:if test="string-length($Title) = 12">
   <!-- Your code here -->
 </xsl:if>
Dimitre Novatchev
+2  A: 

Alternatively you can do the equivalent to and if/else statement in XSL:

<xsl:choose>
  <xsl:when test="string-length($Title) = 12">
    <!-- code when the check is true -->
  </xsl:when>
  <xsl:otherwise>
    <!-- code when it's false -->
  </xsl:otherwise>
</xsl:choose>
Maq
Thank you very much for your help Maq
NWhite
I have seemed to notice that this does not count spaces ' ' .. is there a way to go about having these counted as well?
NWhite