xsl-list
[Top] [All Lists]

Re: [xsl] Using xsl:iterate inside <xsl:for-each-group> xslt 3.0

2020-08-13 14:54:46
Thanks, Martin,

Your response got me thinking. My selection of groups is not specific enough. I 
stepped back to <xsl:for-each> (in place of <xsl:iterate>) to see if I can 
identify the proper level of select. Here is a set of clumsy for-each steps 
that get closer to what I am looking for. Not a final solution, but closer.

                   <write_choices>
                                <xsl:for-each-group select="$myDir/p" 
group-starting-with="span[@class='writeLetter']”> 

                                <!--a variable to keep track of the number of 
spans to select; could iterate this number?-->
                                        <xsl:variable name="groupNum" 
select="1”/>
                                        
                                    
                                    <xsl:for-each 
select="current-group()/span[@class='writeLetter'][$groupNum]">
                                        <xsl:variable name="startNum" 
select="$myitemNum"/>
                                        <write_choice>
                                            <xsl:attribute name="writeNum">
                                                <xsl:value-of 
select="$startNum"/>
                                            </xsl:attribute>
                                            <xsl:attribute name="letter">
                                                <xsl:value-of select="."/>
                                            </xsl:attribute>
                                            <xsl:attribute name="term">
                                                <xsl:value-of 
select="following::span[1]"/>
                                            </xsl:attribute>
                                        </write_choice>
                                    </xsl:for-each>

                                    <xsl:for-each 
select="current-group()/span[@class='writeLetter'][$groupNum + 1]">
                                        <xsl:variable name="startNum" 
select="$myitemNum"/>
                                        <write_choice>
                                            <xsl:attribute name="writeNum">
                                                <xsl:value-of select="$startNum 
+ 1"/>
                                            </xsl:attribute>
                                            <xsl:attribute name="letter">
                                                <xsl:value-of select="."/>
                                            </xsl:attribute>
                                            <xsl:attribute name="term">
                                                <xsl:value-of 
select="following::span[1]"/>
                                            </xsl:attribute>
                                        </write_choice>
                                    </xsl:for-each>

                                </xsl:for-each-group>
                        </write_choices>

Output:

        <write_choices>
            <write_choice writeNum="0" letter="S" term="sentence"/>
            <write_choice writeNum="1" letter="F" term="fragment"/>
         </write_choices>
        …
         <write_choices>
            <write_choice writeNum="1" letter="S" term="sentence"/>
            <write_choice writeNum="2" letter="F" term="fragment"/>
         </write_choices>



Perhaps I need nested <xsl:iterate> statements, one for the groupNum in the 
for-each select and one for the $startNum variable.


On Aug 13, 2020, at 1:26 PM, Martin Honnen 
martin(_dot_)honnen(_at_)gmx(_dot_)de 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

On 13.08.2020 19:15, Terry Ofner tdofner(_at_)gmail(_dot_)com wrote:

Here then is the same section with the <xsl:iterate> added:

<write_choices>
  <xsl:for-each-group select="$myDir/p/*" 
group-starting-with="span[@class='letter']">

     <xsl:iterate select=".">

Inside of any `for-each-group`, the context item `.` is the first item
of `current-group()` so using a single item in the select expression of
`iterate` is likely not what you want.



I haven't grasped what you need instead.

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>