Re: [xsl] Fine tuning a template match

Subject: Re: [xsl] Fine tuning a template match
From: "Jay Bryant" <jay@xxxxxxxxxxxx>
Date: Mon, 31 Jul 2006 10:29:59 -0500
Hi, Trevor,

Now that it's not almost midnight, I'm thinking a bit more clearly.

This kind of problem pops up on the list from time to time. The general
complaint is that "I want to apply a bunch of conditions to a template or a
select attribute." The general course of the discussion goes around and
around with a bunch of different possible solutions until it works but no
one really understands it. The better way, IMHO, is to back up and re-think
what you're trying to do.

So, to borrow some of David's Carlisle usual advice, create an
English-language list of all the cases in which you want to process an A
element. By the time you're done with that, the problem you're having now
will likely be apparent, and you'll know the solution.

I'm not trying to not help you, by the way. I am trying to avoid one of
those round-and-round discussions that this kind of topic generally
produces. So, if you get stumped, post again. Then I (and I bet others) will
try to give more concrete help.

However, any further response from me will have to be much later in the day,
as I must do some work for my client. They'd like to have their project done
on time, and I'd like to get paid, so....

Jay Bryant
Bryant Communication Services


----- Original Message ----- 
From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Monday, July 31, 2006 12:15 AM
Subject: RE: [xsl] Fine tuning a template match


> Hi Jay
>
> > If I understand correctly, you want to narrow the XRefs within tables.
> > If so, could you add [ancestor::TABLE]:
> >
> > <!-- hyperlink targets in rows -->
> > <xsl:template match="A[ ancestor::TABLE ][ @ID ][
> >      not(@CLASS='XRef') ][ not(ancestor::FOOTNOTES) ]">
> >
> > That would ensure that this template matches only A elements
> > that somewhere within tables.
>
> I've tried this: the problem is that it still matches the A elements that
> have already been matched by the moded template.
>
> 1. My various table templates call apply-templates on all A elements that
> appear at any level within the "titles" (which is under CAPTION if the
rows
> are separate, or under CAPTION/TableTitleList if the rows are also under
> CAPTION, or non-existent if this table has no CAPTION at all). This call
to
> apply-templates has a mode (tblhd).
>
> 2. Various templates (those inside rows, but also those inside "title"
> elements) call apply-templates on their own child A elements. These calls
to
> apply-templates are modeless, but unfortunately they include all the A
> elements that were processed by [1] as well.
>
> Cheers
> Trevor
>
> -----Original Message-----
> From: Jay Bryant [mailto:jay@xxxxxxxxxxxx]
> Sent: Monday, 31 July 2006 5:00 p.m.
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] Fine tuning a template match
>
> Hi, Trevor,
>
> I sympathize, as I am doing FrameMaker-to-DocBook for my current client.
>
> If I understand correctly, you want to narrow the XRefs within tables. If
> so, could you add [ancstor::TABLE]:
>
> <!-- hyperlink targets in rows -->
> <xsl:template
>
match="A[ancestor::TABLE][@ID][not(@CLASS='XRef')][not(ancestor::FOOTNOTES)]
> ">
>
> That would ensure that this template matches only A elements that
somewhere
> within tables.
>
> Jay Bryant
> Bryant Communication Services
>
> ----- Original Message ----- 
> From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx>
> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> Sent: Sunday, July 30, 2006 10:56 PM
> Subject: [xsl] Fine tuning a template match
>
>
> > Hi
> >
> > I am trying to transform some FrameMaker-generated XML that contains
lots
> of
> > tables. The tables optionally include a set of titles, and these titles
> are
> > usually wrapped in a caption element - but sometimes the caption element
> > also includes all the table rows :-(
> >
> > Scattered "randomly" through the tables we have <A id=> elements and my
> > requirement is to process all title-related <A> elements before the
table,
> > and all row-related <A> elements within their row. There are <A id=>
> > elements elsewhere in the document, hence some of the conditions in the
> > template which is designed to process them.
> >
> > The following extract successfully identifies the table types and the
<A>
> > elements to be processed at the head of the tables:
> > ==============
> > <!-- tables -->
> > <!-- some tables have one caption child and multiple row children-->
> > <xsl:template match="TABLE[CAPTION and ROW]">
> > <xsl:apply-templates select="CAPTION//A[@ID]" mode="tblhd"/>
> > <xsl:element name="table">...</xsl:element>
> > </xsl:template>
> >
> > <!-- others have all the rows inside the caption -->
> > <!-- in this case the title is wrapped in a titlelist -->
> > <xsl:template match="TABLE[CAPTION/ROW]">
> > <xsl:apply-templates select="CAPTION/TableTitleList//A[@ID]"
mode="tblhd"
> />
> > <xsl:element name="table">...</xsl:element>
> > </xsl:template>
> >
> > <!-- and others have no caption at all -->
> > <xsl:template match="TABLE">
> > <xsl:element name="table">...</xsl:element>
> > </xsl:template>
> >
> > ...
> >
> > <!-- hyperlink targets in headings -->
> > <xsl:template match="A[@ID]" mode="tblhd">
> > ...
> > </xsl:template>
> >
> > <!-- hyperlink targets in rows -->
> > <xsl:template
> match="A[@ID][not(@CLASS='XRef')][not(ancestor::FOOTNOTES)]">
> > ...
> > </xsl:template>
> > ==============
> >
> > As it stands this last template which matches all ID'ed "A" elements in
> > tables causes these elements to be processed twice - once by the moded
> > template and once by the standard template, so that the XML generated
for
> a
> > hyperlink target appears both before the <table> element and once again
> > inside it. So I need to fine tune the final template somehow: I need to
> > exclude the pre-table context from the un-moded template. Does that make
> > sense?
> >
> > Cheers
> > Trevor

Current Thread