I definded the following variables:
<xsl:variable name="pica036E"
select="recordData/record/datafield[@tag='036E']" />
<xsl:variable name="pica036F"
select="recordData/record/datafield[@tag='036F']" />
Now I need to do a condition if variable pica036E isn't empty and pica036F is empty show the following message otherwise show another message. That's my code, but I don't ge any output. Is "null or empty" correct defined?
<xsl:choose>
<xsl:when test="$pica036E != '' and $pica036F = ''">
<xsl:message>
036F no 036E yes
</xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:message>
036E no 036F yes
</xsl:message>
</xsl:otherwise>
</xsl:choose>
XSLT: Check if a string is null or empty. To test if the value of a certain node is empty it depends on what is meant by empty. * Contains no text content: not(string(.)) * Contains no text other than whitespace: not(normalize-space(.))
The XSLT <xsl:value-of> element is used to extract a value from an expression defined in the select attribute. The expression defined in the mandatory select attribute is either an XPATH expression (for nodes and/or values) or a variable reference. The return of the <xsl:value-of> function is a literal value.
Specifies the format pattern. Here are some of the characters used in the formatting pattern: 0 (Digit)
In XPath, X=Y means (if some pair x in X, y in Y satisfy x = y), while X != Y means (if some pair x in X, y in Y satisfy x != y).
This means that if either X or Y is an empty sequence, then both X=Y and X!=Y are false.
For example, $pica036E != ''
tests whether there is a value in $pica036E
that is not a zero-length string. If there are no values in $pica036E
then there is no value that satisfies this condition.
As a result, using != in XPath is always a code smell. Usually, rather than X != Y
, you should be writing not(X = Y)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With