Equivalent to greater than or less than test on strings
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 80
- Joined: Wed Jan 14, 2009 12:50 pm
Equivalent to greater than or less than test on strings
In an XSL transformation I find
works fine as a test so long as the num attributes referenced have numerical values (e.g. when @num is 2 and the equivalent in the preceding sibling is 3, the result is false).
Is there some easy way of doing the same kind of test where the num attributes are, say, single lower-case letters of the alphabet i.e. match [a-z]? I should like to be able to do the same test but where the result is based on alphabetical order, e.g. when the first value is 'a' and the second is 'b' (i.e. to evaluate 'a'<'b' and get false) or vice versa ('b'>'a' to get true). Is there some alternative to the < and > operators that work with strings, or what can be done as a workround?
Code: Select all
<xsl:if test="@num>preceding-sibling::element/@num"> ... </xsl:if>
Is there some easy way of doing the same kind of test where the num attributes are, say, single lower-case letters of the alphabet i.e. match [a-z]? I should like to be able to do the same test but where the result is based on alphabetical order, e.g. when the first value is 'a' and the second is 'b' (i.e. to evaluate 'a'<'b' and get false) or vice versa ('b'>'a' to get true). Is there some alternative to the < and > operators that work with strings, or what can be done as a workround?
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: Equivalent to greater than or less than test on strings
Post by sorin_ristache »
Hello,
Use the compare function:
<xsl:if test="compare(@num, preceding-sibling::element/@num)"> ... </xsl:if>
Regards,
Sorin
Use the compare function:
<xsl:if test="compare(@num, preceding-sibling::element/@num)"> ... </xsl:if>
Regards,
Sorin
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