This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: A question about the expressive power and limitations of XPath 2.0


Dimitre,

>> Hmm... the thing that for expressions can't do it aggregate values
>> over a sequence. An easy one would be a str:concat() function that
>> took a sequence as the argument to be concatenated. This could be
>> implemented by recursion with:
>> 
>> <xsl:function name="str:concat">
>>   <xsl:param name="strings" type="xs:string*" select="()" />
>>   <xsl:param name="concatenated" type="xs:string" />
>>   <xsl:result
>>     select="if (empty($strings))
>>             then $concatenated
>>             else concat($concatenated,
>>                         $strings[1],
>>                         str:concat($strings[position() > 1])" />
>> </xsl:function>
>> 
>
> I thought that you could achieve concatenation by a simple:
>
>  <xsl:value-of select="$sequence" separator="''"/>
>
> or am I wrong? (of course, this is not "pure XPath")

Just had a thought - I think this is still a valid example because
there are certain places where you can't use XSLT - the use attribute
of xsl:key, the select attribute of xsl:sort - so in those situations
you need an XPath expression, can't just use xsl:value-of.

So I think it's still a valid example, especially for xsl:key. There
was a use case mentioned a few days ago, using XForms, where the ref
attribute of xform:bind is a path to an element within xform:instance.
You could solve it with a key if there was some way to generate the
path to an element dynamically. You can get a sequence of strings easy
enough with:

  for $a in (ancestor-or-self::*)
  return (concat('/', name($a), '[',
                 count(preceding-sibling::*[name() = name($a)]) + 1,
                 ']'))

but you can't then turn that sequence into a string within the XPath
(aside from ducking out to user-defined functions and using XSLT and
xsl:value-of, but you said that wasn't allowed).

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]