Jump to content

Compare 2 Strings to See if They are the Same


SteveMurphy
 Share

Recommended Posts

I have two strings and I need to determine if they contain the same characters. I cannot find an "equals" function, so I've come up with a convoluted way of determining string equality:Use the contains() function to see if string2 is in string1If string2 is indeed in string1, then see if the length of the two strings are equal. If they are, then the two strings are equal.I'm using an <xsl:if test=""> element. I get one of my strings from a node using the text() function. The other string is in a variable called methName.I need help with the test attribute.I'd like to combine contains(text(), $methName) and the string-length() function within a test attribute but I'm completely clueless how to do this.It's hard to believe that XSL does not have a function to see if two strings are equal. Did I miss something?

Link to comment
Share on other sites

You can use the string() function to turn a non-text object into a string. If you'll be comparing two nodes, you can always check if one node is equal to the other with a simple "=" like so:

text() = element

This is equivalent to:

string(text()) = string(element)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...