Here's what I have, based on the pattern I see (questions' classes start
with "stem_"). You'll want to remember the key pattern here for future
reference.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="utf-8" indent="yes" omit-xml-declaration="yes"/>
<xsl:key name="questions" match="part/*"
use="generate-id((preceding-sibling::par|self::par)[starts-with(@class,
'stem_')][last()])"/>
<xsl:template match="part">
<xsl:for-each select="par[starts-with(@class, 'stem_')]">
<question>
<xsl:copy-of select="key('questions', generate-id())"/>
</question>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Originally I had omitted the [last()] predicate from the use case,
thinking the preceding-sibling axis would give me the immediate
preceding par as the first result of the node-set, but I was wrong; it
gave the node-set in document order instead, so you need the last one.
The good news is, it works as you'd expect. This is a fairly
straightforward case of grouping, where the generate-id() in the key
links the groups to the nodes that you choose in your template later.
~ Scott
-----Original Message-----
From: Terry Ofner [mailto:tofner(_at_)comcast(_dot_)net]
Sent: Wednesday, January 23, 2008 4:27 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] enclosing siblings in an element
I am a bit stuck on this one. After converting a Word document to rtf
and using upCast I end up with a "flat" structure such as this:
<document>
<part>
<par class="stem_mc">	1	Read the sentence. Then choose the
best synonym to replace the boldfaced word.</par>
<par class="display">The threat of rain makes it <inline
style="font-weight: bold;">dubious</inline> that the game will go on
as scheduled.</par>
<par class="choice-a">	A	doubtful</par>
<par class="choice-b">	B	likely</par>
<par class="choice-c">	C	hopeful</par>
<par class="choice-d">	D	obvious</par>
<par class="Answer">A</par>
<par class="g_code">G5U1S5</par>
<par class="stem_mc">	2	As used in the sentence below,
what is the denotation of the word <inline style="font-style:
italic;">mutt?</inline></par>
<par class="display">"What is that mutt doing in our yard?"
asked Dad.</par>
<par class="choice-a">	A	animal</par>
<par class="choice-b">	B	dog </par>
<par class="choice-c">	C	creature</par>
<par class="choice-d">	D	pet</par>
<par class="Answer">B</par>
<par class="g_code">G5U1S8</par>
<par class="stem_sa">	3	Describe the connotation of the
word <inline style="font-style: italic;">mutt</inline> and explain
wheeher it is positive or negative. </par>
<par class="Answer"><inline style="font-style: italic;"><target
id="OLE_LINK1" /><target id="OLE_LINK2" />Answers will vary. Possible
answer:</inline> The word <inline style="font-style: italic;">mutt</
inline> has the negative connotation of a dog that isn't worth very
much or that isn't good-looking.<endtarget id="OLE_LINK1" /
<endtarget id="OLE_LINK2" /></par>
<par class="g_code">G5U1S8</par>
<--much more like this-->
</part>
</document>
My goal is the wrap each question in a question element:
<question>
<par class="stem_mc">	1	Read the sentence. Then choose the best
synonym to replace the boldfaced word.</par>
<par class="display">The threat of rain makes it <inline
style="font-weight: bold;">dubious</inline> that the game will go on
as scheduled.</par>
<par class="choice-a">	A	doubtful</par>
<par class="choice-b">	B	likely</par>
<par class="choice-c">	C	hopeful</par>
<par class="choice-d">	D	obvious</par>
<par class="Answer">A</par>
<par class="g_code">G5U1S5</par>
</question>
<question>
<par class="stem_mc">	2	As used in the sentence below,
what is the denotation of the word <inline style="font-style:
italic;">mutt?</inline></par>
<par class="display">"What is that mutt doing in our yard?"
asked Dad.</par>
<par class="choice-a">	A	animal</par>
<par class="choice-b">	B	dog </par>
<par class="choice-c">	C	creature</par>
<par class="choice-d">	D	pet</par>
<par class="Answer">B</par>
<par class="g_code">G5U1S8</par>
</question>
<question>
<par class="stem_sa">	3	Describe the connotation of the word
<inline style="font-style: italic;">mutt</inline> and explain wheeher
it is positive or negative. </par>
<par class="Answer"><inline style="font-style: italic;"><target
id="OLE_LINK1" /><target id="OLE_LINK2" />Answers will vary. Possible
answer:</inline> The word <inline style="font-style: italic;">mutt</
inline> has the negative connotation of a dog that isn't worth very
much or that isn't good-looking.<endtarget id="OLE_LINK1" /
<endtarget id="OLE_LINK2" /></par>
<par class="g_code">G5U1S8</par>
</question>
Notice that each question starts with a stem attribute and is
anchored with a g_code attribute. But there can be various <par>
elements between. Is there an easy way to "select" all the <par>
elements between two <par> elements?
Terry Ofner
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--