0

Hi I am wondering is there any function in XSLT 1.0 and XPath 1.0 to behave like java's Appache StringUtils.isBlank(String str)

I use: Edited:

<xsl:variable name="attributeNameValue" select="$sourceObject/attr[@name = $sourceName]" />   
<xsl:if test="$attributeNameValue and not($attributeNameValue='')">
   <!-- Do something-->
</xsl:if>

but I have this check over 100 in all my templates and wonder how to remove it with something faster?

Xelian
  • 16,680
  • 25
  • 99
  • 152

1 Answers1

0

In XPath/XSLT a common check is not(normalize-space($foo)) to check that $foo is an empty string or a pure white space string.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • But what about if it is null - N/A ? – Xelian Oct 04 '16 at 12:08
  • What is a null value in your understanding in the XSLT/XPath 1.0 data model? – Martin Honnen Oct 04 '16 at 12:22
  • If the XPath can not find anything $sourceObject/attr[@name = $sourceName]. So this $sourceName do not exists where we are look for it. – Xelian Oct 04 '16 at 14:52
  • `not(normalize-space($sourceObject/attr[@name = $sourceName]))` is true if an empty node set is selected by `$sourceObject/attr[@name = $sourceName]`. – Martin Honnen Oct 04 '16 at 15:00
  • what if we pass not Xpath but ??? and variable do not have value ? as in the edited example above? is it stil lvalid? – Xelian Oct 04 '16 at 15:13
  • 1
    Given ` ` in XSLT 1.0, the value of the variable is of type node set and of course then the same applies, if the node set is empty then `not(normalize-space($attributeNameValue))` is true as in a string context an empty node set is converted to an empty string (), `normalize-space('')` of an empty string is still an empty string and `not('')` is true. – Martin Honnen Oct 04 '16 at 16:23
  • Ok I check this but it do the opposite thing if I try with boolean(normalize-space($sourceAttribute)) everything behaves as i expected. – Xelian Oct 05 '16 at 07:12