Re: [xsl] Could not select the text() of both parent & child nodes simultaneously

Subject: Re: [xsl] Could not select the text() of both parent & child nodes simultaneously
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Wed, 16 Jun 2010 10:19:08 +0100
On 16/06/2010 09:30, Jack Bush wrote:
Hi David,
I am very new to XML development, not to mention about XSLT

Welcome on board. It's a confusing world, but there are a few things we can try and straighten out for you.
and hesitates to move to version 2.0 for 3 reasons:
( i ) 1.0 is sufficient for what I need to do but there is bound to be better ways to do it in 2.0.
( ii ) XPath& XSLT 2.0 comes at a cost for recent release of Saxon licensing models.
( iii ) Believes that a schema/DTD is required by the stylesheet. Not familiar with how to set it up yet.

There is only really one good reason for using 1.0, and it doesn't apply to you: namely, if there is no XSLT 2.0 processor that works in your chosen environment (and you can't change environment). This primarily applies if you need to do transformations in the browser; it can also apply if you are in a PHP environment on a shared-hosting server, which limits your ability to use Java or .NET.

(i) Even when transformations can be written easily in XSLT 1.0, there's a big productivity gain from using 2.0

(ii) Saxon9 Home Edition provides a "basic XSLT 2.0" processor that is open source

(iii) You don't need to use the schema-aware processing capability of XSLT 2.0 if you don't want to. It offers significant benefits, mainly by detecting errors earlier and therefore reducing the cost of debugging and the dangers of going into production without thorough testing (yes, lots of people do that). But it's an optional feature (and in the case of Saxon, one that isn't available in the open source product).

Any how, below is the error I have encountered after having changed the stylesheet version to 2.0 (line 2):

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
Error on line 83
XPTY0004: Cannot compare java-type:definition.Sport to xs:string
Two points here. Firstly, the fact that you've got a type java-type:definition.Sport suggests that you are using Saxon extensions (or extensibility mechanisms) rather than using pure XSLT 1.0 or XSLT 2.0. I wonder if this is really necessary for your application? Perhaps you are escaping into Java only because that's a more familiar world to you than the world of XSLT? If so, let's see if we can find a way to avoid it.

Secondly, setting version="1.0" on your stylesheet doesn't stop you using XSLT 2.0 features if you're using an XSLT 2.0 processor, but it stops the XSLT 2.0 processor applying the stronger type-checking rules defined in XSLT 2.0. Generally this checking is in your best interests, because it detects many errors in your code. Sometimes it merely prevents the code doing implicit conversions, and makes you write the conversions explicitly - for example, if you're comparing a string to an integer then you have to make it clear whether you want the integer converted to a string or vice-versa.

Back to the original question, what is the XPath statement in XSLT to get the content of both<a> (team) and<p> (goals) at the sametime?

Sorry, I haven't been following the thread that closely.

Michael Kay

Current Thread