xsl-list
[Top] [All Lists]

Re: [xsl] comparing attributes if missing at times

2014-03-26 08:04:52

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



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>