Strange string comparison result

Discussion in 'XML' started by Dankwart Plattner, Aug 21, 2004.

  1. 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.
     
    Dankwart Plattner, Aug 21, 2004
    #1
    1. Advertising

  2. 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/
     
    Martin Honnen, Aug 22, 2004
    #2
    1. Advertising

  3. Dankwart Plattner

    Dankwart Guest

    On Sun, 22 Aug 2004 13:50:00 +0200, Martin Honnen <>
    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!
     
    Dankwart, Aug 22, 2004
    #3
  4. In article <>,
    Dankwart <> 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"
    xmlns:xsl="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>
     
    Richard Tobin, Aug 23, 2004
    #4
  5. Dankwart Plattner

    Dankwart Guest

    Thanks to all contributors. It indeed seems to be a problem with the
    XSLT engine.
    Cheers
    Dankwart
     
    Dankwart, Aug 27, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James

    strange result for String

    James, Aug 3, 2004, in forum: Java
    Replies:
    11
    Views:
    680
    Michael Borgwardt
    Aug 4, 2004
  2. Michael Tan
    Replies:
    32
    Views:
    1,083
    Ara.T.Howard
    Jul 21, 2005
  3. Ryan Wallace

    Strange result using String#split

    Ryan Wallace, Aug 5, 2008, in forum: Ruby
    Replies:
    1
    Views:
    97
    Sebastian Hungerecker
    Aug 6, 2008
  4. Marco Alting

    Strange result in comparison function

    Marco Alting, Sep 19, 2003, in forum: Javascript
    Replies:
    1
    Views:
    90
  5. Deepu
    Replies:
    1
    Views:
    268
    ccc31807
    Feb 7, 2011
Loading...

Share This Page