Re: [xsl] Exclude elements in transformation

Subject: Re: [xsl] Exclude elements in transformation
From: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Thu, 16 Sep 2004 05:21:49 -0700
Im not sure if I completely understand what you are trying to do. Ive checked your mentioned thread it seems that you are really trying to use template matching rules to group/ungroup, include/exclude data elements which is going to be better served by grouping the data together in the correct layout/format first and then apply-templates to the resulting temporary tree. Let me know if the following concept is what you are ultimately attempting to accomplish...

<area>
<section-title>this element could be a title or a subtitle based on whether there are any preceding sections who order of precedence is higher based on a proprietary hierarchal data structure</section-title>
<section-title>If within the same "area" parent there is a preceding-sibling by my same name then I should output as an "h2" element HTML heading tag. If I am the first one then I should be output as an "h1" element tag.</section-title>
<section-title>Im the back-up title in case any of my older brother and sisters lose their birth order or have been banished from the family all together for deeds we won't mention on this family oriented email list.</section-title>
</area>



If the above is anything close to what you are trying to accomplish why not run a first pass of "rules" that are in a separate and maintainable XML file and use document order and structure to determine whether or not an element makes "the cut". For example...


<data rulesStructure="one">
 <a>foo</a>
 <b>foo2</b>
 <c>better than foo!</c>
 <d>foo who?</d>
 <e>i'm an independent</a>
</data>

could easily be pre-processed with:

<rules rulesStructure="one">
<a>
  <b>
    <c priority="1"/>
    <d priority="1"/>
  </b>
</a>
<e alwaysInclude="true"/>
</rules>

These could be "woven" with a pre-processor that would match the ruleStructure attribute value of each XML file and then use the structure of the matching rules element hierarchal data structure to state:

"a" element is king if he maintains.
if "a" chose to entertain over maintain then "b" gets the gig, but if
"b" is out of the question then both "c" and "d" are going to have to do it together until one of them decides to either give it up to the other or somehow find a way to run things together peacefully. We'll keeps tabs on them and change there priority appropriately.
"e" has always been responsible and loved by the family but ultimately is an outsider. He gets precedence only if everyone else is out of the picture but hes always going to be in the family picture even if a half shot of him leaning in to get into the outside view of the lens is all he ever gets.


I realize this is a cheezy example but if the concept is even close to what you are ultimately trying to accomplish as far as making document order and hierarchal decisions as to what does and does not get processed then why not utilize the vast capabilities of describing a HUGE amount of information with a separate and easily maintainable hierarchal-based external rules file that can pre-process the data to the point that in the end the only thing being output is the absolute correct data using standard apply-templates to output things in the correct hierarchal structure and be reassured that if a last minute change shows up it will be taken care by one tiny hierarchal change or priority increase or decrease and then use standard logic building templates and your job is done. A combination of standard template rules, key elements and function, and the generate-id() function and your 95% done...

Let me know if this "concept" helps things and I can help get you going on the right track if necessary...

Best of luck!

<M:D/>


Sonke Ruempler wrote:
Sonke Ruempler <mailto:ruempler@xxxxxxxxxxxxxxx> wrote on Thursday,
September 16, 2004 11:58 AM:


Andrew Welch <mailto:ajwelch@xxxxxxxxxxxxxxx> wrote on
Thursday, September
16, 2004 11:41 AM:


This will do what you ask:

<xsl:template match="*[preceding-sibling::A]"/>

But I suspect there might be a better solution - I think it's
preferable to not select the nodes to process in the first place,
rather than select everything and use a no-op template to suppress
the things you don't want.  You would need to give a little more
information for that kind of answer.

Thx for your quick answer.


Check the thread 'XSLT and FO/FOP workarounding' for details
of my problem -
maybe you know a better solution ;-)



My templates for now are:


[XSLT]
<xsl:template match="h1|h2|h3|h4|h5">
	<fo:table table-layout="fixed" width="100%">
		<fo:table-column
column-width="proportional-column-width(1)"/>
		<fo:table-body>
			<fo:table-row keep-with-next="always">
				<fo:table-cell>
					<fo:block
xsl:use-attribute-sets="name()">
						<xsl:apply-templates/>
					</fo:block>
				</fo:table-cell>
			</fo:table-row>
			<fo:table-row>
				<fo:table-cell>
					<fo:block>
						<xsl:apply-templates
select="following-sibling::*"/>
					</fo:block>
				</fo:table-cell>
			</fo:table-row>
		</fo:table-body>
	</fo:table>
</xsl:template>

<xsl:template match="*[preceding-sibling::(h1|h2|h3|h4|h5)]"/>
[/XSLT]

But that does not work

1. The second element is there twice.
2. The xsl:use-attribute-sets="name()" does not work here.

Any idea?

Current Thread