Patterns in XSL - once again

S

Soren Kuula

Hi,

In XSLT1.0, are these two match expressions not supposed to match the
same nodes:

child::foo

and

foo

?

As I can read the grammar for match expression in the spec, child:; is
implied when there is no / or // at the beginning, and no exlpicit axis.

-- but my xsltproc behaves differently with and without the child:: !

Where is the bug.. ?

Soren
 
D

David Carlisle

Soren Kuula said:
Hi,

In XSLT1.0, are these two match expressions not supposed to match the
same nodes:

child::foo

and

foo

?

As I can read the grammar for match expression in the spec, child:; is
implied when there is no / or // at the beginning, and no exlpicit axis.

-- but my xsltproc behaves differently with and without the child:: !

Where is the bug.. ?

somewhere that you haven't shown us. What different behaviour do you
see?

child::foo and foo are equivalent in XPath expressions an in XSLT match
patterns.


David
 
S

Soren Kuula

Hi,

All right I neglected the example. Here is one:

Input doc:
[dongfang@granada xslt-examples]$ cat position-fun.xml
<?xml version='1.0'?>
<warehouse>
<item name="foo">
<country>Argentina</country>
</item>
<item name="bar">
<country>Brazil</country>
</item>
<item name="baz">
<country>China</country>
</item>

1st stylesheet:
[dongfang@granada xslt-examples]$ cat position-fun21.xsl
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput method="xml" indent="yes"/>

<xsl:template match='warehouse'>
<position-experiment>
<first-try>
<xsl:apply-templates select='item/country | text()'/>
</first-try>
</position-experiment>
</xsl:template>

<xsl:template match='country[1]'>
<first-country>
(with "first", we mean: <xsl:value-of select="position()"/>)
<xsl:copy-of select='.'/>
</first-country>
</xsl:template>

<xsl:template name="notfirst" match='country'>
<xsl:copy-of select='.'/>
</xsl:template>
</xsl:stylesheet>

Output:
[dongfang@granada xslt-examples]$ xsltproc position-fun21.xsl
position-fun.xml
<?xml version="1.0"?>
<position-experiment>
<first-try>
<first-country>
(with "first", we mean: 2)
<country>Argentina</country></first-country>
<first-country>
(with "first", we mean: 4)
<country>Brazil</country></first-country>
<first-country>
(with "first", we mean: 6)
<country>China</country></first-country>
</first-try>
</position-experiment>


2nd stylesheet: Only difference is addition of child:: in match exp

[dongfang@granada xslt-examples]$ cat position-fun22.xsl
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput method="xml" indent="yes"/>

<xsl:template match='warehouse'>
<position-experiment>
<first-try>
<xsl:apply-templates select='item/country | text()'/>
</first-try>
</position-experiment>
</xsl:template>

<xsl:template match='child::country[1]'>
<first-country>
(with "first", we mean: <xsl:value-of select="position()"/>)
<xsl:copy-of select='.'/>
</first-country>
</xsl:template>

<xsl:template name="notfirst" match='country'>
<xsl:copy-of select='.'/>
</xsl:template>
</xsl:stylesheet>

Output:

[dongfang@granada xslt-examples]$ xsltproc position-fun22.xsl
position-fun.xml
<?xml version="1.0"?>
<position-experiment>
<first-try>
<country>Argentina</country>
<country>Brazil</country>
<country>China</country>
</first-try>
</position-experiment>
[dongfang@granada xslt-examples]$

Some difference there.

As I get it, they should have been identical??

Soren
 
S

Soren Kuula

And:
[dongfang@granada xslt-examples]$ xsltproc --version
Using libxml 20606, libxslt 10033 and libexslt 722
xsltproc was compiled against libxml 20511, libxslt 10033 and libexslt 722
libxslt 10033 was compiled against libxml 20511
libexslt 722 was compiled against libxml 20511
 
S

Soren Kuula

David said:
yes, they should.

David

Thanks David,

Getting confused is not that bad after all then, when what you are
trying to convince yourself about is wrong....

Soren
 

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,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top