Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Strange string comparison result

Reply
Thread Tools

Strange string comparison result

 
 
Dankwart Plattner
Guest
Posts: n/a
 
      08-21-2004
Hi,
I hope this is the right group for this question. If not, please point
me to right one.
Some days ago I dared to put my hands on xml for the first time.
I want to compare 2 string values:

1. |<xsl:value-of
select="substring-before(preceding-sibling::track[1]/title,$sepchar)"/>|<br></br>
2. |<xsl:value-of
select="substring-before(preceding-sibling::track[2]/title,$sepchar)"/>|<br></br>
3. <xsl:value-of
select="boolean(substring-before(preceding-sibling::track[1]/title,$sepchar)
=
substring-before(preceding-sibling::track[2]/title,$sepchar))"/><br></br>
4. <xsl:value-of
select="boolean(substring-before(preceding-sibling::track[2]/title,$sepchar)
=
substring-before(preceding-sibling::track[1]/title,$sepchar))"/><br></br>

where $sepchar is ":".
(1) results in |Konzert für Oboe und Orchester|
(2) results in ||
3. is true
4. is true

How could this possibly be?
Thanks for any answer in advance.
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      08-22-2004


Dankwart Plattner wrote:


> Some days ago I dared to put my hands on xml for the first time.
> I want to compare 2 string values:
>
> 1. |<xsl:value-of
> select="substring-before(preceding-sibling::track[1]/title,$sepchar)"/>|<br></br>
> 2. |<xsl:value-of
> select="substring-before(preceding-sibling::track[2]/title,$sepchar)"/>|<br></br>
> 3. <xsl:value-of
> select="boolean(substring-before(preceding-sibling::track[1]/title,$sepchar)
> =
> substring-before(preceding-sibling::track[2]/title,$sepchar))"/><br></br>
> 4. <xsl:value-of
> select="boolean(substring-before(preceding-sibling::track[2]/title,$sepchar)
> =
> substring-before(preceding-sibling::track[1]/title,$sepchar))"/><br></br>
>
> where $sepchar is ":".
> (1) results in |Konzert für Oboe und Orchester|
> (2) results in ||
> 3. is true
> 4. is true
>
> How could this possibly be?


Could you show us the input XML?

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Dankwart
Guest
Posts: n/a
 
      08-22-2004
On Sun, 22 Aug 2004 13:50:00 +0200, Martin Honnen <(E-Mail Removed)>
wrote:


>Dankwart Plattner wrote:
>
>
>> Some days ago I dared to put my hands on xml for the first time.
>> I want to compare 2 string values:
>>
>> 1. |<xsl:value-of
>> select="substring-before(preceding-sibling::track[1]/title,$sepchar)"/>|<br></br>
>> 2. |<xsl:value-of
>> select="substring-before(preceding-sibling::track[2]/title,$sepchar)"/>|<br></br>
>> 3. <xsl:value-of
>> select="boolean(substring-before(preceding-sibling::track[1]/title,$sepchar)
>> =
>> substring-before(preceding-sibling::track[2]/title,$sepchar))"/><br></br>
>> 4. <xsl:value-of
>> select="boolean(substring-before(preceding-sibling::track[2]/title,$sepchar)
>> =
>> substring-before(preceding-sibling::track[1]/title,$sepchar))"/><br></br>
>>
>> where $sepchar is ":".
>> (1) results in |Konzert für Oboe und Orchester|
>> (2) results in ||
>> 3. is true
>> 4. is true
>>
>> How could this possibly be?

>
>Could you show us the input XML?


Thanks for your reaction.
Sure (its over 1400 lines, I stripped it to the bones, preserving the
structure):

<?xml version="1.0"?>
<data>
<fld>
...snip...
</fld>
<record table="album" id="39">
<albumdata>
...snip...
</albumdata>
<trackdata items="1" sides="1">
<item>
...snip...
<side>
...snip...
<track id="452">
...snip...
<title>Toccata und Fuge d-moll BWV 565</title>
...snip...
</track>
<track id="453">
...snip...
<title>Konzert für Oboe und Orchester: Adagio
</title>
...snip...
</track>
<track id="454">
...snip...
<title>Sonate a-dur KV 331: Rondo alla Turca
a-moll</title>
...snip...
</track>
...more tracks here...
</side>
</item>
</trackdata>
</record>
</data>

My actual selected position is the track with id="454". Both
substrings of the preceding-siblings are returned correctly in (1) and
(2) (since the first track title has no $sepchar, the substr returns
an empty string). What compells me is the result of the comparison in
(3) and (4).
Thanks for your effort!

 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      08-22-2004
In article <(E-Mail Removed)>,
Dankwart <(E-Mail Removed)> wrote:

>>> (1) results in |Konzert für Oboe und Orchester|
>>> (2) results in ||
>>> 3. is true
>>> 4. is true
>>>
>>> How could this possibly be?


A bug in the XPath implementation you are using?

If I apply the stylesheet below to your example (using xalan), I get
the expected output

|Konzert f?r Oboe und Orchester|
||
falsefalse

--- Richard

<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="*">
<xsl:apply-templates select="*"/>
</xsl:template>

<xsl:variable name="sepchar">:</xsl:variable>

<xsl:template match="track[3]">
|<xsl:value-of select="substring-before(preceding-sibling::track[1]/title,$sepchar)"/>|
|<xsl:value-of select="substring-before(preceding-sibling::track[2]/title,$sepchar)"/>|
<xsl:value-of select="boolean(substring-before(preceding-sibling::track[1]/title,$sepchar) = substring-before(preceding-sibling::track[2]/title,$sepchar))"/>
<xsl:value-of select="boolean(substring-before(preceding-sibling::track[2]/title,$sepchar) = substring-before(preceding-sibling::track[1]/title,$sepchar))"/>
</xsl:template>

</xsl:stylesheet>
 
Reply With Quote
 
Dankwart
Guest
Posts: n/a
 
      08-27-2004
Thanks to all contributors. It indeed seems to be a problem with the
XSLT engine.
Cheers
Dankwart
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange result using String#split Ryan Wallace Ruby 1 08-06-2008 07:52 AM
Price Comparison Service. Best Deal. Special Coupon atBest-Price-Comparison.com rapee Digital Photography 0 03-14-2008 06:46 AM
1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds Michael Tan Ruby 32 07-21-2005 03:23 PM
strange result for String James Java 11 08-04-2004 08:01 AM
Strange result in comparison function Marco Alting Javascript 1 09-19-2003 10:22 AM



Advertisments