Subject: [xsl] grouping problem From: Terry Ofner <tdofner@xxxxxxxxx> Date: Thu, 15 Apr 2010 18:50:07 -0400 |
I am attempting to group items in a flat file. Here is a sample of the input:
<testbody> <p class="test">A</p> <p class="head-testname">Reading Comprehension</p> <p class="bodytext-directionsrevise">Directions: Read the selection. Then answer the questions that follow.</p> <p class="head-selectiontitle">Jason and the Golden Fleece</p> <p class="bodytext-selectionintro">In Greek mythology, ....</p> <p class="bodytext-numbered">1 King Pelias of Greece, ....</p>
<p class="bodytext-question"><span class="x-qnumber-bold">1</ span>The word invincible in paragraph 14 means</p> <p class="bodytext-choice"> A full of joy.</p> <p class="bodytext-choice"> B not happy.</p> <p class="bodytext-choice"> C having good judgment.</p> <p class="bodytext-choice"> D unable to be defeated.</p>
<p class="bodytext-question"><span class="x-qnumber-bold">2</ span>This story can be described as an epic tale because</p> <p class="bodytext-choice"> F someone with magical powers helps the main character.</p> <p class="bodytext-choice"> G an ordinary person finds courage. </p> <p class="bodytext-choice"> H a hero travels to perform a difficult task for his country. </p> <p class="bodytext-choice"> J a good character confronts evil forces.</p>
<p class="bodytext- directionsrule1">Directions: Read the selection. Then answer the questions that follow.</p> <p class="head-selectiontitle">Freight</p> <p class="bodytext-selectionintro">This is an excerpt ....</p> <p class="bodytext-subhead">Cast of Characters</p> <p class="oldstyles-normal">ABBY, 13 years old</p> <p class="oldstyles-normal">LABAN, a slave owner</p> <p class="oldstyles-normal">TUCKER, his overseer</p>
<p class="bodytext-question"><span class="x-qnumber-bold">11</ span>Why are some .... parentheses?</p> <p class="bodytext-choice"> A to tell the actors what to do</p> <p class="bodytext-choice"> B to tell a narrator what to say</p> <p class="bodytext-choice"> C to tell what sound effects to use</p> <p class="bodytext-choice"> D to tell the audience what is going on</p>
Here is the basic grouping 2.0 template (xsl:attribute elements have been removed) in which I am trying to group the @class='bodytext- question and @class=bodytext-choice elements:
<xsl:template match="testbody"> <testbody> <xsl:for-each-group select="*" group-starting-with="p [@class=('bodytext-question','bodytext-questionfirst')]"> <xsl:choose> <xsl:when test="following-sibling::p [@class='bodytext-choice'][4]"> <xsl:text> </ xsl:text><xsl:element name="question">
<xsl:apply-templates select="current-group()"/>
</ xsl:element><xsl:text> </xsl:text> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="current- group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </testbody> </xsl:template>
This template works for bodytext-questions that are followed by other bodytext-questions. But it also groups everything from the start of <testbody> to the first bodytext-question as well as everything that follows the last of a series of bodytext-questions.
<testbody> <question> <p class="test">A</p> <p class="head-testname">Reading Comprehension</p> <p class="bodytext-directionsrevise">Directions: Read the selection. Then answer the questions that follow.</p> <p class="head-selectiontitle">Jason and the Golden Fleece</p> <p class="bodytext-selectionintro">In Greek mythology, ....</p> <p class="bodytext-numbered">1 King Pelias of Greece, ....</p> </question> <question> <p class="bodytext-question"><span class="x-qnumber-bold">1</ span>The word invincible in paragraph 14 means</p> <p class="bodytext-choice"> A full of joy.</p> <p class="bodytext-choice"> B not happy.</p> <p class="bodytext-choice"> C having good judgment.</p> <p class="bodytext-choice"> D unable to be defeated.</p> </question> <question> <p class="bodytext-question"><span class="x-qnumber-bold">2</ span>This story can be described as an epic tale because</p> <p class="bodytext-choice"> F someone with magical powers helps the main character.</p> <p class="bodytext-choice"> G an ordinary person finds courage. </p> <p class="bodytext-choice"> H a hero travels to perform a difficult task for his country. </p> <p class="bodytext-choice"> J a good character confronts evil forces.</p>
<p class="bodytext- directionsrule1">Directions: Read the selection. Then answer the questions that follow.</p> <p class="head-selectiontitle">Freight</p> <p class="bodytext-selectionintro">This is an excerpt ....</p> <p class="bodytext-subhead">Cast of Characters</p> <p class="oldstyles-normal">ABBY, 13 years old</p> <p class="oldstyles-normal">LABAN, a slave owner</p> <p class="oldstyles-normal">TUCKER, his overseer</p> </question> <question> <p class="bodytext-question"><span class="x-qnumber-bold">11</ span>Why are some .... parentheses?</p> <p class="bodytext-choice"> A to tell the actors what to do</p> <p class="bodytext-choice"> B to tell a narrator what to say</p> <p class="bodytext-choice"> C to tell what sound effects to use</p> <p class="bodytext-choice"> D to tell the audience what is going on</p> </question>
I suspect that I should be using group-adjacent but am I unsure how to go ahead with such grouping in this case.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Grouping problem, Joel Dubien | Thread | RE: [xsl] grouping problem, Michael Kay |
Re: [xsl] how to decode Base64 in X, Florent Georges | Date | RE: [xsl] grouping problem, Michael Kay |
Month |