Subject: [xsl] How to set an element as the context without using a for-each loop? From: "Roger L Costello costello@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 1 May 2024 11:28:27 -0000 |
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? /Roger
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Thread | Re: [xsl] How to set an element as , David Carlisle d.p.c | |
Date | Re: [xsl] How to set an element as , David Carlisle d.p.c | |
Month |