Exactly for this reason, I once suggested to add <xsl:with> (or maybe:
<xsl:with-context>) to the language. It would be like <xsl:for-each>,
but has the benefit that there could be a check if the select-expression
really matches only one item, not more. There can be discussion on
whether or not to allow the select-expression to match an empty sequence.
Currently, I use to add a comment to my <xsl:for-each> that explains
that it will iterate only once.
Pieter
On 5/1/24 13:31, David Carlisle d.p.carlisle@xxxxxxxxx wrote:
>
> B <xsl:sequence
> select="$record/(f:convert(Customer_or_Area_Code),f:convert(Cycle_Date),f:convert(Sequence_Number))"/>
>
> David
>
> On Wed, 1 May 2024 at 12:28, Roger L Costello costello@xxxxxxxxx
> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Hi Folks,
>
> I have a function that I pass "record" to:
>
> <xsl:function name="f:procedureLeg" as="element()+">
> B B B B <xsl:param name="record" as="element()"/>
> B B B B ...
> </xsl:function>
>
> "record" is an element that contains a bunch of child elements
> which the function must process.
>
> So, "record" is the context for those child elements.
>
> One approach to process the child elements is to qualify them with
> "$record/" like this:
>
> <xsl:function name="f:procedureLeg" as="element()+">
> B B B B <xsl:param name="record" as="element()"/>
>
> B B B B <xsl:sequence
> select="f:convert($record/Customer_or_Area_Code)"/>
> B B B B <xsl:sequence select="f:convert($record/Cycle_Date)"/>
> B B B B <xsl:sequence select="f:convert($record/Sequence_Number)"/>
> B B B ...
> </xsl:function>
>
> That's horrible. Qualifying every child element is tedious and
> error prone (I am likely to forget to qualify some child elements).
>
> Another approach, which avoids qualifying every child element, is
> to set the context via a for-each loop:
>
> <xsl:function name="f:procedureLeg" as="element()+">
> B B B B <xsl:param name="record" as="element()"/>
>
> B B B B <xsl:for-each select="$record">
> B B B B B B B <xsl:sequence select="f:convert(Customer_or_Area_Code)"/>
> B B B B B B B <xsl:sequence select="f:convert(Cycle_Date)"/>
> B B B B B B B <xsl:sequence select="f:convert(Sequence_Number)"/>
> B B B B B B ...
> B B B </xsl:for-each>
> </xsl:function>
>
> That's lousy as well. "record" is just a single element; I
> shouldn't be looping over a single element (in my opinion).
>
> Is there a better way? One that doesn't involve qualifying every
> child element and doesn't involve looping over a single element?
>
> /Roger
>
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/3208261>
> (by email <>)
|