Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Patterns in XSL - once again

Reply
Thread Tools

Patterns in XSL - once again

 
 
Soren Kuula
Guest
Posts: n/a
 
      03-17-2005
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
 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      03-17-2005
Soren Kuula <(E-Mail Removed)> writes:

> 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
 
Reply With Quote
 
 
 
 
Soren Kuula
Guest
Posts: n/a
 
      03-17-2005
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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput 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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput 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

 
Reply With Quote
 
Soren Kuula
Guest
Posts: n/a
 
      03-17-2005

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



 
Reply With Quote
 
David Carlisle
Guest
Posts: n/a
 
      03-17-2005

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


yes, they should.

David
 
Reply With Quote
 
Soren Kuula
Guest
Posts: n/a
 
      03-17-2005
David Carlisle wrote:
>>As I get it, they should have been identical??

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

 
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
Birthday time once again! Silverstrand The Lounge 6 07-10-2005 07:29 PM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
How to include several xsl files from a same directory at once? Julien Phalip XML 0 02-17-2005 10:53 PM
Regex to match say char 't' exactly once in a string and no more than once Gancy Perl Misc 4 02-03-2005 02:19 PM
where to find good patterns and sources of patterns (was Re: singletons) crichmon C++ 4 07-07-2004 10:02 PM



Advertisments