[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: comparing strings
Dimitre Novatchev wrote: > The node-set() extension function has to be used -- however it will be > standard in XSLT 1.1. OK, Taking into account that strings do not exist "by themselves" in an XML document, but are always values of some kind of node (e.g. text, attribute, comment, namespace) -- then here's a solution that compares the string value of two nodes -- ***no extension functions are used***. xml document (testStringCompare.xml): ------------------------------------ <cities> <city>Paris</city> <city>London</city> <city>Sydney</city> <city>New York</city> </cities> stylesheet(StringCompare.xsl): ---------------------------- <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' > <xsl:output method="text"/> <xsl:template match="/"> <xsl:variable name="node1" select="/cities/city[3]"/> <xsl:variable name="node2" select="/cities/city[2]"/> <xsl:value-of select="$node1"/> <xsl:text> is</xsl:text> <xsl:call-template name="node-stringCompare"> <xsl:with-param name="node1" select="$node1"/> <xsl:with-param name="node2" select="$node2"/> </xsl:call-template> <xsl:value-of select="$node2"/> </xsl:template> <xsl:template name="node-stringCompare"> <xsl:param name="node1"/> <xsl:param name="node2"/> <xsl:choose> <xsl:when test="string($node1)=string($node2)"> <xsl:text> equal to </xsl:text> </xsl:when> <xsl:otherwise> <xsl:for-each select="$node1 | $node2"> <xsl:sort select="."/> <xsl:if test="position()=1"> <xsl:choose> <xsl:when test="string(.) = string($node1)"> <xsl:text> less than </xsl:text> </xsl:when> <xsl:otherwise> <xsl:text> greater than </xsl:text> </xsl:otherwise> </xsl:choose> </xsl:if> </xsl:for-each> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> Result: -------- Sydney is greater than London Cheers, Dimitre Novatchev. __________________________________________________ Do You Yahoo!? Yahoo! Photos - Share your holiday photos online! http://photos.yahoo.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|