RE: [xsl] The notion of Inheritance?

Subject: RE: [xsl] The notion of Inheritance?
From: William Bagby <williamb@xxxxxxxxx>
Date: Thu, 29 Mar 2001 16:47:21 -0500
Jeni,

Thanks, works like a charm.

Now lets add a couple of wrinkles to it...

1. Suppose I'm using person[id = 1] as the default, but now person[id = 2]
(or any person for that matter) can contain nodes that are not in the
default. I want all the nodes of person[id = 2], plus the nodes from
person[id = 1] (I guess this is the union in mathematical terms).

2. Suppose I add an <address> node that looks like this:

<person>
	<id>2</id>
	...
	<address>
		<country>USA</country>
		<state>NY</state>
		<city>New York</city>
		...
	</address>
	...
</person>

But for another person, it may look like this:

<person>
	<id>5</id>
	...
	<address>
		<country>Canada</country>
		<province>NY</province>
		<city>New York</city>
		...
	</address>
	...
</person>

So, in the default case person[id = 1], I want something like this:

<person>
	<id>1</id>
	...
	<address>
		<country>USA</country>
		<state>NY</state>
		<city>New York</city>
		...
	</address>
	<address>
		<country>Canada</country>
		<province>ONT</province>
		<city>Toronto</city>
		...
	</address>
</person>

and I want to be able to get the defaults for only that persons' country
(which must be specified).  This is looking (and feeling) more and more like
a Relational DB, I guess, but is this possible?  Or is there a better way to
structure the XML in the first place?  I don't even know if a DTD will allow
this sort of thing.


Thanks again,

William.


-----Original Message-----
From: Jeni Tennison [mailto:mail@xxxxxxxxxxxxxxxx]
Sent: Thursday, March 29, 2001 1:19 PM
To: William Bagby
Cc: XSL Mailing List (E-mail)
Subject: Re: [xsl] The notion of Inheritance?


Hi William,

> I was a bit hasty with my reply.

Ahh, good.  I was a bit confused by it.

> I also cannot figure out how to prevent the rest of the data 
from passing
> through.

If you select what to process with an xsl:apply-templates, then the
processor won't process the bits you don't select.  I just posted
giving a demonstration of that.

>   Normally I would use something like:
>
> <xsl:template match="*|@*|text()">
> <!-- do nothing! -->
> </xsl:template>
>
> but that doesn't work here, as you've already matched *[*] and
> *[not(*)], which seems to cover pretty much everything, although I
> could be (and probably am!) mistaken.

Those templates are assigned a different ('inherit') mode, so they'll
only be applied when templates are applied in 'inherit' mode.  So you
could use an empty default template like the one above if you wanted.

However, usually if you only want to process a little bit of your file
it's more efficient to tell the processor to only process that bit (a
pull approach) rather than getting it to process everything (which is
what it does by default) and only give templates for the things you're
interested in (a push approach).

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread