xsl-list
[Top] [All Lists]

Re: [xsl] processing following-siblings to a point

2009-07-10 00:22:08
With due respect to the proponents of XSLT 2.0, sometimes a project
dictates the choice of processor, so it's XSLT 1.0 or bust.  Maybe
this isn't the case for Charles, but I'll use it as a "literary
device", for the moment.  And, while I'm a big fan of recursion,
having paid my dues in the DSSSL world, it's not an implementation
choice to be made lightly, regardless of experience.

That said, and with a nod to C. Michael, I'll make a couple of
suggestions and leave the remaining fun up to Charles.  First, while
your sample input happens to always have a subtitle right after each
title, I suspect the real thing might have multiple subtitles under a
single title.  To accommodate this, and to keep your transform a
little simpler, I suggest you build only a single level of your output
structure in any given template.

Second, in selecting a set of input elements to process at a given
level, one thing they should all have in common is the number of
preceding siblings that are instances of the element one level up in
the hierarchy.  For example, all paras that "belong" to the same
subtitle should have the same number of subtitle elements as preceding
siblings.  This number can be easily determined while you're
processing the subtitle to which the paras belong.

Hopefully, this is enough to get you headed in a viable direction,
should you choose to remain in the XSLT 1.0 space.

-Brandon :)

On Thu, Jul 9, 2009 at 2:59 PM, <charlieo0(_at_)comcast(_dot_)net> wrote:
Hello all,

I've run into a structure that I must transform that I just haven't found a 
solution for. XSL 1.0 only. (I just don't have the proficiency for 2.0 yet).

I'm transforming what was a rather flat SGML structure to an XML structure. 
 Here's the input structure:

<gen>
<title>TITLE_1</title>
<subtitle>SUBTITLE_1</subtitle>
<para>Text.</para>
<para>Text.</para>
<para>Text.</para>
<title>TITLE_2</title>
<subtitle>SUBTITLE_2</subtitle>
<para>Text.</para>
<para>Text.</para>
<para>Text.</para>
<para>Text.</para>
<title>TITLE_2</title>
<subtitle>SUBTITLE_2</subtitle>
<para>Text.</para>
<para>Text.</para>
<para>Text.</para>
<para>Text.</para>
</gen>

Resulting structure tree:

<para0>
<title>TITLE_1</title>
<subpara1>
<title>SUBTITLE_1</title>
<para>Text.</para>
<para>Text.</para>
<para>Text.</para>
</subpara1>
</para0>
<para0>
<title>TITLE_2</title>
<subpara1>
<title>SUBTITLE_2</title>
<para>Text.</para>
<para>Text.</para>
<para>Text.</para>
<para>Text.</para>
</subpara1>
</para0>
<para0>
<title>TITLE_3</title>
<subpara1>
<title>SUBTITLE_3</title>
<para>Text.</para>
<para>Text.</para>
<para>Text.</para>
<para>Text.</para>
<para>Text.</para>
</subpara1>
</para0>

My template (or at least the important part).

   <xsl:template match="gen/title" mode="move">
       <para0>
           <title>
               <xsl:value-of select="."/>
           </title>
           <subpara1>
               <title><xsl:value-of 
select="following-sibling::subtitle[1]"/></title>
               <xsl:apply-templates select="following-sibling::para"/>
           </subpara1>
       </para0>

My problem is with the <xsl:apply-templates 
select="following-sibling::para"/> line. Of course, all of the para elements 
are following siblings of all the gen/title elements. How can I express the 
<apply-templates> to process only the para element siblings BEFORE the next 
following title sibling. (This is difficult because EVERYTHING is a sibling 
of everything else).

Charles Flanders
IETM Developer


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

<Prev in Thread] Current Thread [Next in Thread>