|
Subject: Re: [xsl] Using xsl:iterate inside <xsl:for-each-group> xslt 3.0 From: "Terry Ofner tdofner@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 18 Aug 2020 17:55:43 -0000 |
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> </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="	1.	Sent the
package to her yesterday."/>
<write_choice spanNum="1" letter="S" term="sentence" ans="	1.	Sent the
package to her yesterday."/>
<write_choice spanNum="2" letter="S" term="sentence" ans="	2.	A
history teacher at the middle school."/>
<write_choice spanNum="3" letter="S" term="sentence" ans="	2.	A
history teacher at the middle school."/>
<write_choice spanNum="4" letter="S" term="sentence" ans="	3.	Roberto
works on Saturday afternoons."/>
<write_choice spanNum="5" letter="S" term="sentence" ans="	3.	Roberto
works on Saturday afternoons.b/>
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> </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 donbt
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 fragmentb/>
>> <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.
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Using xsl:iterate inside , Terry Ofner tdofner@ | Thread | Re: [xsl] Using xsl:iterate inside , Martin Honnen martin |
| Re: [xsl] Using xsl:iterate inside , Terry Ofner tdofner@ | Date | Re: [xsl] Using xsl:iterate inside , Martin Honnen martin |
| Month |