Reputation: 5250
1) How to check if the number variable has only 4 digits using XSL1.0.
<xsl:variable name="number" select="0715" />
2) How to check if the version variable has a numeric digit followed by an upper case using XSL1.0
<xsl:variable name="version" select="V1" />
Upvotes: 0
Views: 144
Reputation: 163262
1) How to check if the number variable has only 4 digits using XSL1.0.
<xsl:variable name="number" select="0715" />
This is impossible, because the value of $number is exactly the same as if you wrote
<xsl:variable name="number" select="715" />
The insignificant zero disappears long before you can test for its presence. So perhaps you just want ($number < 10000)
?
On the other hand, if you're testing that a string comprises exactly four digits, use translate($x, '0123456789', '9999999999') = '9999'
.
2) How to check if the version variable has a numeric digit followed by an upper case using XSL1.0
Depends a little what you mean by "followed" - can there be anything in between? If you mean 'immediately followed', then you can use the same trick:
translate(substring($x, 1, 1), '0123456789', '9999999999') = '9'
and
translate(substring($x, 2, 1), 'ABCD...XYZ', 'Z') = 'Z'
Upvotes: 2
Reputation: 116959
Use the string-length()
function to determine the ... well, the length of a string.
You could test for:
translate($version, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 'AAAAAAAAAAAAAAAAAAAAAAAAAA0000000000') = 'A0'
Note: This tests for a single upper case character followed by a single digit - IOW, the string "V1" passes this test.
Note also that your variable points to an element named V1
, not to a string containing "V1".
Upvotes: 1