xsl-list
[Top] [All Lists]

Re: [xsl] grouping based on string but with child nodes

2008-10-13 11:18:19
2008/10/13 James Cummings <cummings(_dot_)james(_at_)gmail(_dot_)com>:
Hiya,

I have some old EAD XML that I'm trying to convert to a slightly
better form and what I want to take is something like this:

<unittitle>
   <title>Calendarial rules. Prognostics. || Alcuin,
       <emph render="italic">Quaestiones in Genesim</emph>. ||
       Glossaries. || <emph render="italic">Ps</emph>.-Cicero,
       <emph render="italic">Synonyma ad Lucium Veturium</emph>, with
added Latin-Old English
       glossaries extracted from the Grammar and Glossary of Ælfric.
   </title>
   <!-- other elements -->
</unittitle>

where several titles are grouped together into a single title element
and delineated by two vertical bars || and split this into properly
grouped elements without loss of the <emph> elements.  I'll be
combining this with some other similarly split up data (about time
periods of the works) into a new structure.  So desired output (in a
variable since I then need to count them and create those other
structures one for each of these) something like:

<unittitle>
   <title>Calendarial rules. Prognostics.</title>
   <title>Alcuin, <emph render="italic">Quaestiones in Genesim</emph>. 
</title>
   <title>Glossaries. </title>
   <title>
       <emph render="italic">Ps</emph>.-Cicero,
       <emph render="italic">Synonyma ad Lucium Veturium</emph>,
       with added Latin-Old English glossaries extracted from the Grammar
       and Glossary of Ælfric. </title>
   <!-- other elements -->
</unittitle>

I've been assuming that this is a two-pass problem where I have to
replace the '||' with some empty XML element  and then group-by that
element?  If that is the case what is the best way to replace these
for grouping?  Or is it possible to do this all-in-one?  XSLT2
solution obviously desired to avoid too much recursion. :-)

Yes, use 2 passes, it will help you diagnose problems in the 2nd pass
much more easily.

The first pass is an idenity transform with:

<xsl:template match="title">
  <xsl:for-each select="tokenize(., '||')>
    <title><xsl:value-of select="."/></title>

For the second pass it's not clear to me how you want to group them,
so maybe post back with an example if you need to.



-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

--~------------------------------------------------------------------
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>
--~--