Re: Options as strings. Blech.

On 2 September 2011 19:50, Norman Walsh wrote:

  Hi,

> <xsl:value-of select="(1,2)"/> => "1 2"

  This one uses the algorithm in [1] to construct a string out of
the sequence.

> <xsl:value-of select="string((1,2))"/> => err:XPTY004

  This one is a type error because the function string()'s
argument is item()? and you pass a sequence of 2 items.

  BTW, I don't know where this message comes from, but the error
code must be XPTY0004 (with 3 zeros) and not XPTY004 (with only 2
zeros).  Either a C'nP error or a typo in the processor (Saxon I
guess).

> Not sure which of those we should be doing.

  The spec says, about p:with-option/@select: "when XPath 2.0 is
being used, the value is an xs:untypedAtomic."  So I'd thend to
say it implies err:XPTY0004, but this sentence can be interpreted
differently by others.

  In my opinion, the safest is to raise an error, and if the user
really wants to accept sequences, then he/she has to specify
explicitely what to do, for instance:

    <xsl:value-of select="
        string-join(for $i in (1, 2) return string($i))"/>

  That's a bit more verbose, but that's the less-surprise path:
the user has to explicit what to do in such cases.  The problem
is that the XSLT algorithm to construct simple content is very
convenient in lots of cases, but it is not available as one
single standard function (and it is more complex than the example
above in the general case).  It could probably be provided
through a new XProc function, say p:string() or p:make-string(),
refering explicitely to [1]:

    <p:with-option ... select="p:string((1, 2))"/> => "1 2"

  Regards,

-- 
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/

[1] http://www.w3.org/TR/xslt20/#constructing-simple-content

Received on Sunday, 4 September 2011 16:28:46 UTC