xsl-list
[Top] [All Lists]

Re: [xsl] Help cleaning up this 1.0 gem

2007-10-06 03:30:15
David Carlisle wrote:
anything with lots of conditional arithemetic expressions is
likely to be easier to maintain in xslt 2 rather than 1, so upgrading
now rather than later should (or could) be considered.

IIRC, then the last post of Steve was about some classic (faq?) encoding problem with MSXML (msxml always outputting a sub-perfect UTF-16, regardless of the xsl:output settings). Along the lines it showed that he's running things in plain old ASP (pre-2000?) and thus is burdened by a legacy system that is likely quite hard to upgrade (not being .NET).

On the other hand, it shouldn't be too hard (actually, quite easy) to create a COM+ object in .NET that can be called from any plain old ASP application (or VB or VBA for that matter). This will also ease the pain of workarounds for indentation, encoding and other xsl:output settings. This brings up the possibility to use .NET 2.0 with older legacy applications.

Without being able to run it, yor code sample is rather too long to
grock by eye so cant make too many comments, but beware != any stylesheet
that uses it is liable to strange bugs. In teh cases where != doesn't do
the same thing as not (  = ) then it almost aways does the wrong thing.

Just to summarize for the unaware, I think David means the following:

<list>
   <item>test</item>
   <item>test-wrong</item>
</list>
<list>
   <item>test-good</item>
</list>

using <xsl:value-of select="list/item != test" /> will output 'true', because there are elements that are unequal to 'test'. Likewise, the following are all true:

<xsl:value-of select="list/item != list/item" />
<xsl:value-of select="//item != //item" />
<xsl:value-of select="//item[1] != //item[1]" />
<xsl:value-of select="list/item != 'whateverstring' " />

Conversely, the following are all false, mainly because the first <item> is implicitly or explicitly tested:

<xsl:value-of select="string(//item) != string(//item)" />
<xsl:value-of select="string(list/item) != string(list/item)" />
<xsl:value-of select="string(list/item) != 'test-wrong' " />
<xsl:value-of select="(//item)[1] != (//item)[1]" />

Be aware of the brackets! These four are all different (though some provide the same result):

<xsl:value-of select="list/item != list/item" />
<xsl:value-of select="(list/item)[1] != (list/item)[1]" />
<xsl:value-of select="list[1]/item != list[1]/item" />
<xsl:value-of select="list[1]/item[1] != list[1]/item[1]" />

Finally, be *very* aware of empty selections (this includes typos, which is why people love XSLT 2.0 with validation so much!), because they are always FALSE when comparing the two, completely contrary to intuition (all the below are FALSE):

<xsl:value-of select="list/notexistingnode != list/item" />
<xsl:value-of select="list/notexistingnode[1] != list/item[1]" />
<xsl:value-of select="list/item[10] != list/item[10]" />
<xsl:value-of select="list/item[10] = list/item[10]" />
<xsl:value-of select="list/notexistingnode = list/item[1]" />
<xsl:value-of select="list/notexistingnode > list/item[1]" />
<xsl:value-of select="list/notexistingnode &lt; list/item[1]" />
<xsl:value-of select="list/item[10] >= list/item[10]" />

Yes, indeed, even '=' returns false. This (and all the rest) is why David says '=' is not the opposite of '!=', in many cases it can yield the same result....

Cheers,
-- Abel Braaksma




--~------------------------------------------------------------------
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>