[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] grouping problem
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> </testbody>
<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: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> </testbody> I suspect that I should be using group-adjacent but am I unsure how to go ahead with such grouping in this case. Terry
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|