[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: compare two nodes (the child elements, not the str
Hi,
A generalization of Michael's suggestion is to use a mode in which each element is processed to write strings, and then compare the strings. So: <xsl:variable name="author-string"> <!-- generating an RTF containing a string --> <xsl:apply-templates select="$author" mode="string"/> </xsl:variable> <xsl:variable name="person-string"> <!-- again --> <xsl:apply-templates select="$person" mode="string"/> </xsl:variable> <xsl:if test="$author-string = $person-string"> ... You can then manage how each string is generated, for purposes of comparison, using templates matching in the mode. (You will find you need to do some of this in order, for example, to normalize whitespace.) To compare an author to more than one person, wrap your calls in a template that writes a result string you can test for. So: <xsl:template name="compare-person"> <xsl:param name="author" select="/.."/> <xsl:param name="person" select="."/> <xsl:variable name="author-string"> <xsl:apply-templates select="$author" mode="string"/> </xsl:variable> <xsl:variable name="person-string"> <xsl:apply-templates select="$person" mode="string"/> </xsl:variable> <xsl:if test="$author-string = $person-string"> TRUE </xsl:if> </xsl:template> Then: <xsl:template match="author"> <xsl:variable name="author" select="."/> <xsl:variable name="compare-result"> <xsl:for-each select="$persons"> <!-- generating an RTF containing a string, possibly including 'TRUE' --> <xsl:call-template name="compare-person"> <xsl:with-param name="author" select="$author"> </xsl:call-template> <xsl:for-each> </xsl:variable> <xsl:if test="contains($compare-result,'TRUE')"> ... Note this doesn't tell you which of your persons is (are) the same as your author. For that you have to work harder (there are ways). This little exercise in XSLT 1.0 may well convince you that life is easier under XSLT 2.0. Cheers, Wendell On 7/6/2011 4:22 PM, Michael M|ller-Hillebrand wrote: Am 06.07.2011 um 20:54 schrieb Wolfhart Totschnig:
|
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
|