6

I have the following which checks for a string within the xml... however, I need to create another test to check for 'Null' or no text within the variable $validItems at the 1st line...

<xsl:if test="$validItems[(Caption | CalltoAction)[string(.)]]">
 <div class="text">
   <xsl:choose>
     <xsl:when test="$horizontal">
       <div class="holder">
         <div class="frame">
           <div class="slides-descriptions">
             <xsl:apply-templates select="$validItems" mode="horizontal"/>
           </div>
           <div class="switcher"/>
         </div>
       </div>
     </xsl:when>
     <xsl:otherwise>
       <div class="slides-descriptions">
         <xsl:apply-templates select="$validItems" mode="vertical"/>
       </div>
       <div class="switcher"/>
     </xsl:otherwise>
   </xsl:choose>
 </div>
</xsl:if>

How would I go about testing the variable xsl:if test=$validItems?

Bobulous
  • 12,967
  • 4
  • 37
  • 68
MizAkita
  • 1,115
  • 5
  • 21
  • 52
  • 2
    Have you try `xsl:if test="not($validItems)"` or read http://www.w3.org/TR/xpath/#section-Boolean-Functions ? – Istao Mar 25 '13 at 17:58
  • 1
    It's not clear what you want to do. "another test to check for 'Null' or no text within the variable $validItems" - Do you want to check whether *any* of the elements in `$validItems` have a `Caption` or `CalltoAction` child element whose text value is an empty string? BTW there's not really such thing as "null" in XSLT, just empty strings / node-sets / sequences. – LarsH Mar 25 '13 at 18:28
  • I want to look within $validItems for no text within Caption|CalltoAction. If no text is found I need condition. I am only looking for how to filter if there is no text in the string. – MizAkita Mar 25 '13 at 18:56

3 Answers3

7

If I understand what you're asking for,

<xsl:if test="$validItems[(Caption | CalltoAction)[not(string(.))]]">

will do it. In other words, "if there is an element in the $validItems node-set that has a Caption or CalltoAction child element whose string value is empty". You could also say

<xsl:if test="$validItems[(Caption | CalltoAction)[. = '']]">
LarsH
  • 27,481
  • 8
  • 94
  • 152
6

There is no such thing as "Null" in the XPath data model.

As for "no text within the variable $validItems" it would help to know the type of this variable. If it's a single element node (as might appear from the code sample you have shown), and what you want to test is that it has no text node children, the test would be not($ValidItems/text()). If you want to test that it has no text node descendants, try not(string($validItems)) or equivalently, $validItems=''.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
0

None of these answers worked for me, I don't know if its because I'm using xpath via ODK xforms. I did get it working using this solution:

string-length(string(/path/to/node)) = 0

I have tested this on dates and numbers.

Ring
  • 2,249
  • 5
  • 27
  • 40