Created
February 8, 2011 23:32
-
-
Save greystate/817527 to your computer and use it in GitHub Desktop.
One-liner to assign a variable one of two values, dependent on condition (XSLT 1.0, that is)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Selects 'YES' if CONDITION is true() --> | |
<xsl:value-of select="substring('YES|NO', not(CONDITION) * 4 + 1, 3)" /> | |
<!-- Selects 'NO' if CONDITION is true() --> | |
<xsl:value-of select="substring('YES|NO', boolean(CONDITION) * 4 + 1, 3)" /> | |
<!-- | |
Notes: | |
* Need both versions because the longer value must be the first of the two | |
* 4 is the index of the pipe (|) character (or the string-length of the first value plus one) | |
* 3 is the string-length of the first value | |
Credit goes to Jeni Tennison - I saw this used a couple of times in her excellent book "XSLT and XPath on the Edge". | |
--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment