How to test empty strings
Oxygen general issues.
-
- Posts: 6
- Joined: Mon Mar 24, 2008 4:05 pm
How to test empty strings
hi,
I am trying to print a message when a string is empty.
This works well if the nonempty_string has a value. In other words, for an empty string I am not able to print "None".
I am trying to print a message when a string is empty.
Code: Select all
<xsl:variable name="nonempty_string" select="n2:Protocol/n2:FundingSource/n2:FundingSourceName"/>
<xsl:variable name="empty_string" />
<xsl:choose>
<xsl:when test="$nonempty_string != $empty_string" >
<xsl:apply-templates />
</xsl:when>
<xsl:otherwise >
<fo:inline>None</fo:inline>
</xsl:otherwise>
</xsl:choose>
-
- Posts: 501
- Joined: Mon Feb 03, 2003 10:56 am
Re: How to test empty strings
The variable empty_string must be initialized to an empty string. See the following example:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="nonempty_string" select="'alpha beta'"/>
<xsl:variable name="empty_string" select="''"/>
<xsl:choose>
<xsl:when test="$nonempty_string != $empty_string">
When
</xsl:when>
<xsl:otherwise>
Otherwise
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Please consult an XSLT tutorial, like the one you may find here:
http://www.zvon.org/xxl/XSLTutorial/Boo ... index.html
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="nonempty_string" select="'alpha beta'"/>
<xsl:variable name="empty_string" select="''"/>
<xsl:choose>
<xsl:when test="$nonempty_string != $empty_string">
When
</xsl:when>
<xsl:otherwise>
Otherwise
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Please consult an XSLT tutorial, like the one you may find here:
http://www.zvon.org/xxl/XSLTutorial/Boo ... index.html
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service