[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: grouping flat structure, part two

Subject: Re: grouping flat structure, part two
From: Terry Ofner <tofner@xxxxxxxxxxx>
Date: Fri, 25 Jan 2008 12:07:26 -0500
Re:  grouping flat structure
I have worked a bit more on my grouping problem. I have solved the narrative group this way:

<xsl:template match="part">
<xsl:for-each-group select="par[@class='NarrBody']" group- adjacent="name()">
<narrative>
<xsl:for-each select="current-group()">
<xsl:value-of select="preceding-sibling::par[1]/node()"/>
<xsl:apply-templates select="."/>
</xsl:for-each>
</narrative>
</xsl:for-each-group>



Since the questions really don't have similar adjacent attributes, I am not sure how to start. Perhaps start with the @class="choice-x"?


t.o.

On Jan 25, 2008, at 9:38 AM, Terry Ofner wrote:

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">&#9;5.1&#9;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">&#9;A&#9;definition 1</par>
<par class="choice-b">&#9;B&#9;definition 2</par>
<par class="choice-c">&#9;C&#9;definition 3</par>
<par class="choice-d">&#9;D&#9;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>&#9;device for measuring weight</par>
<par class="NarrBody"><inline style="font-weight: bold;">scale</ inline>&#9;series of steps or degrees </par>
<par class="NarrBody"><inline style="font-weight: bold;">scaln</ inline>&#9;series of musical notes</par>
<par class="NarrBody"><inline style="font-weight: bold;">scale</ inline>&#9;outer body layer of fish and snakes</par>


<par class="stem_mc">&#9;6.2&#9;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">&#9;A&#9;device for measuring weight</par>
<par class="choice-b">&#9;B&#9;series of steps or degrees</par>
<par class="choice-c">&#9;C&#9;series of musical notes</par>
<par class="choice-d">&#9;D&#9;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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.