Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT/XPath test for 'Null'

Tags:

xml

xslt

xpath

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?

like image 846
MizAkita Avatar asked Mar 25 '13 16:03

MizAkita


1 Answers

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)[. = '']]">
like image 115
LarsH Avatar answered Oct 23 '22 15:10

LarsH