Search

I'm having a problem filtering empty textareas in XSLT having changed the configuration of an existing web site with existing entries.

Former entries without text in a textarea field I have, seem to have NULL for both value and value_formatted in the database and when I attempt to filter with a simple for-each statement in xslt all goes well.

My textarea is named "description"

My for-each statement is in the form of

<xsl:for-each select="entry/location-entries/item[description = '']">

However, if I save a new entry or edit and existing one but leave the description field empty the corresponding line in the database still has NULL for value field but the value-formatted field becomes empty(that is nothing in it), and my for-each statement fails to catch that item.

So it appears that description = '' relates only to value-formatted = NULL. How can I catch these completely empty fields with my for-each?

A solution or advice would be much appreciated, is there another way to say empty?

I'm using Symphony 2.3 BTW.

Erm, forgot to say, this is a SSM of "location-entries" included in an entry. Not sure if that's relevant.

Try:

<xsl:for-each select="entry/location-entries/item[normalize-space(description) = '']">

That should select items without description and with description like:

  • <description></description>
  • <description/>
  • <description><p></p></description>

Big thanks ahwayakchih that works fine.

I'm confused as to why though, I'll go look up "normalize-space" and find out.

Thanks again :)

So, I think this works because where the content of my database value-formatted field appeared to be empty, its content wasn't actually an empty string it was just a generic nothing.

My attempt to

...item[description = '']...

Was trying to match the field contents with an empty string which failed.

...item[normalize-space(description) = '']...

As well as stripping white-space also converts the node contents to a string and so it could be matched with my empty string selector.

It seems good to use normalise-space as it will also deal with other cases as ahwayakchih shows above, rather than just my case which is to do with string type content.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details