[Home] [By Thread] [By Date] [Recent Entries]
Thanks to those that showed me how to use for-each-group (group-
starting-with). That would be a wonderful solution except that I have
intervening elements that I need to keep out of each group. Here is
an updated snapshot of my input:
<document> <part> <par class="stem_mc">	5.1	Which definition of key matches how the word is used in the following sentence?</par> <par class="display">What key should I play that in?</par> <par class="choice-a">	A	definition 1</par> <par class="choice-b">	B	definition 2</par> <par class="choice-c">	C	definition 3</par> <par class="choice-d">	D	definition 4</par> <par class="answer">D</par> <par class="g_code">G5U1S9</par> <par class="NarrIntro">2. Directions: Study the homographs. Then answer the related question(s).</par> <par class="NarrBody"><inline style="font-weight: bold;">scale</ inline>	device for measuring weight</par> <par class="NarrBody"><inline style="font-weight: bold;">scale</ inline>	series of steps or degrees </par> <par class="NarrBody"><inline style="font-weight: bold;">scaln</ inline>	series of musical notes</par> <par class="NarrBody"><inline style="font-weight: bold;">scale</ inline>	outer body layer of fish and snakes</par> <par class="stem_mc">	6.2	Which meaning of scale is used in the sentence below?</par> <par class="display">The butcher put the meat on the scale.</par> <par class="choice-a">	A	device for measuring weight</par> <par class="choice-b">	B	series of steps or degrees</par> <par class="choice-c">	C	series of musical notes</par> <par class="choice-d">	D	outer body layer of fish and snakes</par> <par class="answer">A</par> <par class="g_code">G5U1S7</par> </part> </document> I need to group each question from @stem_mc to @g_code . Along the way I need to group narratives from @NarrIntro to the last @NarrBody. Since the narratives looked easier, I tried the following group- adjacent template to group them. <xsl:template match="part"> <xsl:for-each-group group-adjacent="@class='NarrBody'" select="*"> <narrative> <xsl:apply-templates select="preceding-sibling::par[1]/node()"/> <xsl:apply-templates select="current-group()"/> </narrative> </xsl:for-each-group> </xsl:template> The above template produces the following output. <?xml version="1.0" encoding="UTF-8"?> <document> <part> <narrative> <par class="stem_mc"> 5.1 Which definition of key matches how the word is used in the following sentence?</par> <par class="display">What key should I play that in?</par> <par class="choice-a"> A definition 1</par> <par class="choice-b"> B definition 2</par> <par class="choice-c"> C definition 3</par> <par class="choice-d"> D definition 4</par> <par class="answer">D</par> <par class="g_code">G5U1S9</par> <par class="NarrIntro">2. Directions: Study the homographs. Then answer the related question(s).</par> </narrative> <narrative>2. Directions: Study the homographs. Then answer the related question(s).<par class="NarrBody"> <inline style="font-weight: bold;">scale</inline> device for measuring weight</par> <par class="NarrBody"> <inline style="font-weight: bold;">scale</inline> series of steps or degrees </par> <par class="NarrBody"> <inline style="font-weight: bold;">scaln</inline> series of musical notes</par> <par class="NarrBody"> <inline style="font-weight: bold;">scale</inline> outer body layer of fish and snakes</par> </narrative> <narrative> <inline style="font-weight: bold;">scale</inline> outer body layer of fish and snakes<par class="stem_mc"> 6.2 Which meaning of scale is used in the sentence below?</par> <par class="display">The butcher put the meat on the scale.</par> <par class="choice-a"> A device for measuring weight</ par> <par class="choice-b"> B series of steps or degrees</ par> <par class="choice-c"> C series of musical notes</par> <par class="choice-d"> D outer body layer of fish and snakes</par> <par class="answer">A</par> <par class="g_code">G5U1S7</par> </narrative> </part> I am obviously missing something. Any hints would be appreciated. Terry
|

Cart



