Recipe 2.1. Testing If a String Ends with Another StringProblemYou need to test if a string ends with a particular substring. SolutionXSLT 1.0substring($value, (string-length($value) - string-length($substr)) + 1) = $substr XSLT 2.0ends-with($value, $substr) DiscussionXSLT 1.0 contains a native starts-with() function but no ends-with() . This is rectified in 2.0. However, as the previous 1.0 code shows, ends-with can be implemented easily in terms of substring( ) and string-length() . The code simply extracts the last string-length($substr) characters from the target string and compares them to the substring.
|