xsl-list
[Top] [All Lists]

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

2020-08-18 12:55:51
Hmm. The map:merge appears to fiddle with the ?letter and the ?term. It appears 
that the position() is coming from the $groups map. Not sure why the letter is 
stuck on S and the term on sentence. Do I need an argument within the map merge 
to tell how to merge the two? 

<xsl:iterate select="for $p in p[@class = 'nl'] return $groups ! 
map:merge(($groups, map { 'p' : $p }))">
                        
                        <xsl:text>&#10;</xsl:text>
                        <write_choice  spanNum="{position() - 1}" 
letter="{?letter}"
                            term="{?term}" ans="{?p}"/>
 </xsl:iterate>

Output.

<write_choice spanNum="0" letter="S" term="sentence" ans="&#x9;1.&#x9;Sent the 
package to her yesterday."/>
<write_choice spanNum="1" letter="S" term="sentence" ans="&#x9;1.&#x9;Sent the 
package to her yesterday."/>
<write_choice spanNum="2" letter="S" term="sentence" ans="&#x9;2.&#x9;A history 
teacher at the middle school."/>
<write_choice spanNum="3" letter="S" term="sentence" ans="&#x9;2.&#x9;A history 
teacher at the middle school."/>
<write_choice spanNum="4" letter="S" term="sentence" ans="&#x9;3.&#x9;Roberto 
works on Saturday afternoons."/>
<write_choice spanNum="5" letter="S" term="sentence" ans="&#x9;3.&#x9;Roberto 
works on Saturday afternoons.”/>



I did experiment a bit with map:merge by creating another variable / map.

<xsl:variable name="answers" as="map(xs:string, xs:anyAtomicType)*">
                    <xsl:for-each select="p[@class='nl']">
                        <xsl:variable name="item">
                            <xsl:analyze-string select="." 
regex="\t\t?(\d\d?)\.\t">
                                <xsl:matching-substring>
                                    <xsl:value-of select="regex-group(1)"/>
                                </xsl:matching-substring>
                            </xsl:analyze-string>
                        </xsl:variable>
                       <xsl:sequence select="map {'num': $item}"></xsl:sequence>
                    </xsl:for-each>
                </xsl:variable>

With this iterate

<xsl:iterate select="p[@class='nl'] ! map:merge(($groups, $answers), 
map{'duplicates':'combine'})">
                        <xsl:text>&#10;</xsl:text>
                        <write_choice  spanNum="{position() - 1}" pNum="{?num}" 
letter="{?letter}"
                            term="{?term}"/>
                        
                    </xsl:iterate>

I get the following output in which the sequence inside my $answer map don’t 
work as I planned but I get all the letters and terms. 

<write_choice spanNum="0" pNum="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" letter="S 
F" term="sentence fragment"/>
<write_choice spanNum="1" pNum="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" letter="S 
F" term="sentence fragment"/>
<write_choice spanNum="2" pNum="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" letter="S 
F" term="sentence fragment"/>
<write_choice spanNum="3" pNum="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" letter="S 
F" term="sentence fragment"/>
<write_choice spanNum="4" pNum="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" letter="S 
F" term="sentence fragment”/>


<xsl:apply-templates
       select="for $p in p[@class = 'nl']
               return $groups
                      !
                      map:merge(
                        ($groups,
                         map { 'p' : $p })
                      )"/>

or the same expression for the iterate.

--~----------------------------------------------------------------
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>