Re: [xsl] Use of data() function

Subject: Re: [xsl] Use of data() function
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Wed, 5 Mar 2008 10:49:17 +0000
On 05/03/2008, Michael Kay <mike@xxxxxxxxxxxx> wrote:
> >
>  > ...which is a bit odd to me at the moment.  It seems a bit of
>  > an artificial restriction.
>  >
>
> The basis for the distinction is the theory that with mixed content, it
>  makes sense to treat the markup as mere decoration of the text, whereas with
>  element-only content, concatenating the children is a meaningless operation.
>  In both cases I think the assumption is probably correct 95% of the time,
>  and in the 5% of cases where it's wrong, the rule doesn't do much harm.

That's a nice way of putting it.

It is slightly funny though, that given:

<data>
  <somedata>important data</somedata>
  <somedata>even more important data</somedata>
</data>

calling data() on that results in an error, and that's at the request
of the data heads.

Intuitively (for me at least) I would expect it to concatenate the
data items with a space separator.  Where the content was mixed, you
wouldn't need the separator.

Perhaps the data() function should be avoided - just use the
appropriate constructor instead.  For example, the data(@married)
example[1] - as long as @married is typed then test="data(@married)"
will work as expected.  If it's untyped and @married="false" then
data(@married) returns true, so the result will change depending on
whether the source has been validated or not.

If however you do test="xs:boolean(@married)" then it works as
expected regardless of validatation.

[1] http://schema-aware.com/xslt/data-function.html


-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

Current Thread