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

Re: grouping question

Subject: Re: grouping question
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 25 Nov 2010 23:11:05 +0000
Re:  grouping question
On 25/11/2010 21:56, Birnbaum, David J wrote:
Dear XSLT List,

I'm trying to create build a hierarchy from structure that has been
encoded with milestone tags. The source xml looks like:

<block ref="282r1"> <hm281><pb folio="282r"/><rubric>blah blah
bl<lb/>ah.</rubric></hm281> <hm280><pb folio="257r"/><rubric>blah
blah blah</rubric></hm280> <hm282><pb folio="297v"/><rubric>blah blah
blah</rubric>  <lb/></hm282> </block> <block ref="282r2">
<hm281><rubric>blah blah blah.</rubric>  <lb/></hm281>
<hm280><rubric>blah<lb/>  blah blah.</rubric>  <lb/></hm280>
<hm282><rubric>blah blah blah</rubric>  <lb/></hm282> </block>
<!-lots more blocks -->

This is an interlinear collation of three manuscripts, from which I
need to generate separate output for each manuscript that restores
the original pagination and lineation. Page breaks are encoded with
empty<pb/>  milestones that record the page number on a @folio
attribute. Line breaks are encoded with empty<lb/>  milestones; the
line number is calculated by counting the number of lines from the
most recent page break.

The strategy I've used--which almost works--is to group by<pb>  and
then process each of those groups by grouping by<lb>:

<xsl:for-each-group select="$root//*[name() eq $currentms]/node()"
group-starting-with="pb"> <tr> <th colspan="2"> <xsl:value-of
select="@folio"/> </th> </tr> <xsl:for-each-group
select="current-group()" group-starting-with="lb"> <tr> <th>
<xsl:value-of select="position()"/> </th> <td class="os">
<xsl:apply-templates select="current-group()"/> </td> </tr>
</xsl:for-each-group> </xsl:for-each-group>

The only place where this breaks is in the<hm280>  line of the
second<block>  element in the snippet at the top of this message,
where it fails to find the<lb>  embedded in the<rubric>.

isn't this also a problem in the first rubric of the first block, which also has a nested lb ?


I think I
understand why; it is grouping the children of the group delimited
by<pb>  elements, so the<rubric>  is a unit, and it doesn't flatten
the hierarchy deeply enough to dig inside it.

This is the only misfire and I can fix it in a few ways (including
fiddling with the source xml), but is there a standard strategy for
flattening all the way down, grouping by<lb>  elements no matter how
deeply they're embedded in the group delimited by the<pb>  elements?

It depends a bit what you want to do once you've found them. You don't show what your other templates are doing. If you are just extracting text then the fact that the lb is nested isn't really a problem, jusy select all the leaf nodes ie replace


<xsl:for-each-group select="current-group()"
    group-starting-with="lb">


by


<xsl:for-each-group select="current-group()/descendant-or-self::node()[not(node()]"
group-starting-with="lb">


But if you need to copy the existing element structure, or equivalently generate a new structure from it, then it depends how you want to restart your elements.

So if for example you want to split on <lb/> putting each row into an html <tr><td>...</td></tr>

then if <rubric> is being translated to (say) <span> you presumably need to force it to close at the <lb/> but restart afterwards.

<span>blah blah blah</span><span>blah </span></td></tr>
<tr><td><span> blah blah.</span><td></tr>


that's a bit harder one way is to do a first pass that turns everything into empty (milestone) elements denoting the start and end of elements, then it is all on one level and you can use grouping to reconstruct the re-ordered tree.


David






I realize now that I've never had to more than one level deep for
this type of project before.

Thanks,

David (djbpitt@xxxxxxxx)


________________________________________________________________________



This e-mail has been scanned for all viruses by Star.
________________________________________________________________________

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.