-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of
Hahn, Andrea
Sent: 02 September 2003 12:20
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] XPath: excluding a descendant
Hello David and Michael,
thanks for your answers and sorry for my bad explanation! I
am not sure if the empty template is really the way to go,
though, because the "everything else" is my problem. To
illustrate this a bit better: from the XML fragment below, I
want to create some "dump" output like "6.5.1995 Smith
somedescription Ireland 100.0" (just some example), but
excluding the "29.16" of <LongitudeDecimal>. All of the
elements are in the same namespace. So what I am casting
around for is how to form the predicate in a way that I get
any data from <Gathering> and below, except for that one. I
had been thinking that
<xsl:apply-templates
select="abcd:Gathering[not(.//*[self::abcd:LongitudeDecimal])]"/>
would be the way to go; but this snipps all the content from
the <Site> node and below as soon as a <LongitudeDecimal>
exists (which is optional), not just the <LongitudeDecimal>
element itself. I guess this is something really stupid, but
I don't seem to be able to solve it. Thanks for your patience!
You're misunderstanding how apply-templates works. If you do
apply-templates select="abcd:Gathering" then you select all the
abcd:Gathering elements that are children of the context node, and
process them. There's only one such node, and you want to modify the way
it is processed, not the way it is selected.
I don't understand why the empty template rule doesn't work for you. Is
it because there is another LongtudeDecimal element under
<somethingElse> that is to be processed differently? If that's the case,
either use modes, or write the rule as
<xsl:template match="Gathering//LongitudeDecimal"/>
Michael Kay
Andrea
<TopNode>
<aLotOfStuff>
<...>
</aLotOfStuff>
<Gathering>
<GatheringDate>
<DateText>6.5.1995</DateText>
</GatheringDate>
<Collectors>
<Collector>
<CollectorText>Smith</CollectorText>
</Collector>
</Collectors>
<Site>
<LocalityText>some description</LocalityText>
<Country>
<CountryName>Ireland</CountryName>
</Country>
<CoordinateSets>
<Coordinates>
<LatLong>
<LongitudeDecimal>29.16</LongitudeDecimal>
</LatLong>
</Coordinates>
</CoordinateSets>
<Altitude>100.0</Altitude>
</Site>
</Gathering>
<somethingElse>
<...>
</somethingElse>
</TopNode>
-----Original Message-----
From: Michael Kay [mailto:mhk(_at_)mhk(_dot_)me(_dot_)uk]
Sent: Dienstag, 2. September 2003 10:03
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] XPath: excluding a descendant
The aim:
For providing some quick-and-dirty html output, just making
sure all data are in there somehow, I want to "dump" all
content below a certain node (not the root element) to the
screen. There is, however, one sub-sub-sub-node whose
contents I want to display on its own in a more structured
way, and I do not want it duplicated in the dump. Following
the suggestions I could find for selecting all children
except for one in the FAQ I constructed this:
<xsl:apply-templates
select="abcd:Gathering[not(self::LongitudeDecimal)]"/>
This will process all the abcd:Gathering elements that are
not LongitudeDecimal elements. Of course, none of them are.
Without seeing the structure of your XML I find it difficult
to tell you the correct code.
But the simplest way of not processing a particular element (and its
children/descendants) is to write an empty template rule for it:
<xsl:template match="LongitideDecimal"/>
Michael Kay
where Gathering is the top node for the dump, and
Gathering/GatheringSite/SiteCoordinates/LongitudeDecimal the
one node I would want _not_ to display. This does not work at
all, I guess because the element-to-exclude is not a child,
but a descendant (?). If I change the line above to
"...not(descendant::...", I get a different effect: not
excepting the one element from the output, but just testing
on presence of the node, with everything being displayed when
"LongitudeDecimal" does not exist, but nothing when it does.
How can I achieve to always display everything, always
without the Longitude-content?
Thanks,
Andrea
XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
XSL-List info
and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list