Strange string comparison result

D

Dankwart Plattner

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.
 
M

Martin Honnen

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?
 
D

Dankwart

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!
 
R

Richard Tobin

[/QUOTE]

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

Dankwart

Thanks to all contributors. It indeed seems to be a problem with the
XSLT engine.
Cheers
Dankwart
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top