xsl-list
[Top] [All Lists]

Re: [xsl] Combining consecutive siblings

2006-06-13 02:47:40
On 6/13/06, Trevor Nicholls <trevor(_at_)castingthevoid(_dot_)com> wrote:
Hi Andrew

Thank you very much. Just a few concluding notes:

1.
----
<xsl:template match="CELL">
<td><xsl:apply-templates select="SB"/></td>
</xsl:template>
----

I know my example didn't show it, but in Real Life there are an awful lot of
things in CELLs, and every so often amongst them there is a run of SB
elements which I want to collapse in this way. So the above is too simple,
unfortunately. (There also may be two runs of SB with some other intervening
element, as well.)

Yes, sorry, that should have been

<xsl:template match="CELL">
<td><xsl:apply-templates/></td>
</xsl:template>

...for the very reason that youv'e found - you want to apply-templates
to all elements, and just do nothing <SB> elements that arent the
first in a sequence of <SB> elements as they will be processed by a
moded template.

2.
----
<xsl:template match="SB[preceding-sibling::*[1][self::SB]]" priority="2"/>
----

This I have added - it should kick in for any SB selected (without a mode)
whether or not 'select="SB"' was specified on the apply-templates node,
right?

Correct.

3.
When I experimented by interspersing random elements amongst the SB runs, I
found that they were each appearing twice. I see now, I think, that Dr Kay's
templates presumed that the "higher-order" template was only selecting the
first <B> child, hence the need to include
----
<xsl:apply-templates select="following-sibling::*[not(self::b)][1]"/>
----
(or [not(self::SB)] in my case) after the closing <B> in the main template.
As my "higher-order" template (I don't know what the canonical term is,
sorry) is simply doing a general <apply-templates /> then non-SB children
are pulled in anyway. So I dropped that line as well.

Correct, you don't need that line if the template matching the parent
element has called apply-templates.  You would need that line if the
parent called apply-templates on the first element only, and then each
template would call apply-templates on the appropriate
following-sibling.  Its just two different ways of walking the tree.

On the samples I have tried since making these changes, it seems now to be
doing what I want.

great.

cheers
andrew

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