Re: [xsl] How to set an element as the context without using a for-each loop?

Subject: Re: [xsl] How to set an element as the context without using a for-each loop?
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 1 May 2024 12:09:26 -0000
On 01/05/2024 13:28, Roger L Costello costello@xxxxxxxxx wrote:
> Hi Folks,
>
> I have a function that I pass "record" to:
>
> <xsl:function name="f:procedureLeg" as="element()+">
>          <xsl:param name="record" as="element()"/>
>         ...
> </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()+">
>          <xsl:param name="record" as="element()"/>
>
>         <xsl:sequence select="f:convert($record/Customer_or_Area_Code)"/>
>         <xsl:sequence select="f:convert($record/Cycle_Date)"/>
>         <xsl:sequence select="f:convert($record/Sequence_Number)"/>
>        ...
> </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()+">
>          <xsl:param name="record" as="element()"/>
>
>         <xsl:for-each select="$record">
>               <xsl:sequence select="f:convert(Customer_or_Area_Code)"/>
>               <xsl:sequence select="f:convert(Cycle_Date)"/>
>               <xsl:sequence select="f:convert(Sequence_Number)"/>
>              ...
>        </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?
>
 B  <xsl:sequence select="$record ! (Customer_or_Area_Code, Cycle_Date,
Sequence_Number) ! f:convert(.)"/>

Current Thread