Re: [xsl] Member function?

Subject: Re: [xsl] Member function?
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 2 Aug 2022 15:04:18 -0000
I would also comment that you need to wean yourself off using document('') to
read data held in the stylesheet.

Firstly, it only works if the source code of the stylesheet is available at
run-time, and if its base URI is known. There are all sorts of operational
circumstances where that might not be true.

Secondly, it's ludicrously expensive: because the whitespace rules for
document() and different from the rules for stylesheets, it means the
stylesheet has to be reparsed and another copy of the tree kept in memory.

It's a workaround for the silly result-tree-fragment problem in XSLT 1.0 and
needs to be consigned to the dustbin of history. Use a global variable
instead.

Michael Kay
Saxonica

> On 2 Aug 2022, at 15:57, Dave Pawson dave.pawson@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Tue, 2 Aug 2022 at 15:54, Michael Kay mike@xxxxxxxxxxxx
<mailto:mike@xxxxxxxxxxxx>
> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx
<mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>> wrote:
>>
>> I would always use a map for this in XSLT 3.0, rather than a node tree; and
then use map:contains() to check if a value is present.
>
> <grin/> OK. Not something I've used Mike.
> I had the index for a sort by date, hence thought to use it again.
>
> I'll play with that, live and learn!
>
> Thank you.
>
>
>
>>
>> Michael Kay
>> Saxonica
>>
>>> On 2 Aug 2022, at 15:50, Martin Honnen martin.honnen@xxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>>>
>>>
>>> Am 02.08.2022 um 16:10 schrieb Dave Pawson dave.pawson@xxxxxxxxx:
>>>> xpath 2 or 3
>>>>
>>>> I have a sort index
>>>> <d:sort_index name="my_sort">
>>>>    <d:entry key="Jan" index="0"/>
>>>>    <d:entry key="Feb" index="1"/>
>>>>    <d:entry key="Mar" index="2"/>
>>>>    <d:entry key="Apr" index="3"/>
>>>>    <d:entry key="May" index="4"/>
>>>>    <d:entry key="Jun" index="5"/>
>>>>    <d:entry key="Jul" index="6"/>
>>>>    <d:entry key="Aug" index="7"/>
>>>>    <d:entry key="Sep" index="8"/>
>>>>    <d:entry key="Oct" index="9"/>
>>>>    <d:entry key="Nov" index="10"/>
>>>>    <d:entry key="Dec" index="11"/>
>>>>
>>>>  </d:sort_index>
>>>>
>>>>  <xsl:variable name="sort_index" select="document('')//d:sort_index"/>
>>>
>>>
>>> Given that you say XPath 2 or 3 I assume XSLT 2 or 3 so I would prefer a
>>> variable or parameter e.g.
>>>
>>>
>>> <xsl:variable name="sort-index">
>>>
>>>   <d:entry key="Jan" index="0"/>
>>>   <d:entry key="Feb" index="1"/>
>>>   <d:entry key="Mar" index="2"/>
>>>   <d:entry key="Apr" index="3"/>
>>>   <d:entry key="May" index="4"/>
>>>   <d:entry key="Jun" index="5"/>
>>>   <d:entry key="Jul" index="6"/>
>>>   <d:entry key="Aug" index="7"/>
>>>   <d:entry key="Sep" index="8"/>
>>>   <d:entry key="Oct" index="9"/>
>>>   <d:entry key="Nov" index="10"/>
>>>   <d:entry key="Dec" index="11"/>
>>>
>>> </xsl:variable>
>>>
>>> and then a key
>>>
>>> <xsl:key name="sort-index" match="d:entry" use="@key"/>
>>>
>>>
>>> and then a check on
>>>
>>>   key('sort-index', tokenize(d, ' '), $sort-index)
>>>
>>> or
>>>
>>>  key('sort-index', tokenize(d, '')[1], $sort-index)
>>>
>>>> and xml with many
>>>>
>>>> <book>
>>>>      <author>
>>>>        <f>H</f>
>>>>        <s>Stone</s>
>>>>      </author>
>>>>      <t>Jane Doe</t>
>>>>      <d>Jul 2018</d>
>>>>    </book>
>>>>
>>>> I want to check that the d element (month) has an entry in the sort
>>>> index using xsl:for-each over //book/d
>>>>
>>>> Suggestions please?
>>>>
>>>> TiA
>>>>
>>>>
>>>
>>>
>>
>>
>
>
> --
> Dave Pawson
> XSLT XSL-FO FAQ.
> Docbook FAQ.

Current Thread