[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
see the comments about != in the recent thread on text() (if you followed it that far:-)
Applying != to sequences that you do not know have exactly 1 element is well defined but rarely useful.
Given
compare the results of
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
you get:
Note that string() ensures that you get exactly one value (a possibly empty string) rather than @x which may return a sequence of length 0 or 1.
David
Re: [xsl] comparing attributes if missing at times
Subject: Re: [xsl] comparing attributes if missing at times From: David Carlisle <davidc@xxxxxxxxx> Date: Wed, 26 Mar 2014 13:04:15 +0000 |
see the comments about != in the recent thread on text() (if you followed it that far:-)
Applying != to sequences that you do not know have exactly 1 element is well defined but rarely useful.
Given
<x> <elem x="1"/> <elem x="1"/> <elem x="2"/> <elem/> <elem x="3"/> </x>
compare the results of
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="elem"> <elem
test1="{@x != preceding-sibling::elem[1]/@x}" test2="{not(@x = preceding-sibling::elem[1]/@x)}" test3="{string(@x) != preceding-sibling::elem[1]/string(@x)}" test4="{not(string(@x) = preceding-sibling::elem[1]/string(@x))}" > <xsl:copy-of select="@*"/> </elem> </xsl:template> </xsl:stylesheet>
you get:
<elem test1="false" test2="true" test3="false" test4="true" x="1"/> <elem test1="false" test2="false" test3="false" test4="false" x="1"/> <elem test1="true" test2="true" test3="true" test4="true" x="2"/> <elem test1="false" test2="true" test3="true" test4="true"/> <elem test1="false" test2="true" test3="true" test4="true" x="3"/>
Note that string() ensures that you get exactly one value (a possibly empty string) rather than @x which may return a sequence of length 0 or 1.
David
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] comparing attributes if missi, Szabo, Patrick (LNG- | Thread | Re: [xsl] comparing attributes if m, Michael Kay |
[xsl] comparing attributes if missi, Szabo, Patrick (LNG- | Date | Re: [xsl] comparing attributes if m, Michael Kay |
Month |