xsl-list
[Top] [All Lists]

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

2009-07-09 19:15:47
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 think you've got that the wrong way around. With positional grouping in
XSLT 2.0 (<xsl:for-each-group group-starting-with="title">) this is quite an
easy problem. In XSLT 1.0 you need to write recursive templates, which
requires a much higher level of proficiency in the language.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 



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



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