Preserve ancestors/discard children

Subject: Preserve ancestors/discard children
From: John Robert Gardner <jrgardn@xxxxxxxxx>
Date: Sun, 19 Dec 1999 01:22:03 -0500 (EST)
For the following XML, I'm trying to "shave off" all the <ul>'s, each of 
of which has only a "class="L"" attribute to distinguish its <li>'s.  In
other
I only want to have everything from <li class="T"> UPWARD, with _none_ of
the 
sub-ul's therein.  I realize it's kind of hackneyed html, but it was
pre-xhtml
hybrid stuff, and the copyright doesn't allow me to freely distribute the
"L"
version.  The intent is to give a sample file to some rather courageous 
scholars of Tantra who want to play with XSL for mantra studies. I'll be
cleaning
it up after I slash the unreleased material.

What I'm not getting, is how to get the whole tree above the element
selected 
(e.g., give me all <li class="T"> and it's parents, but none of its
children.

<?xml version="1.0"?>
<thml>
<body bgcolor="#ffffff">

<div class="Rgveda">
<div1 class="maNDala" id="1">
<dl>
<div2 class="hymn" id="1.1">
<div3 class="verse" id="1.1.1">
<a name="1.1.1"></a>
<dt>1.1.1</dt>
<dd>
<ol class="mantra" type="a">
	<li class="T">
agni;m ILe puro;hitaM yajJa;sya deva;m Rtvi;jam /
<ul><li class="L">
agni;m ILe puro;hitam</li>
<li class="L">
yajJa;sya deva;m Rtvi;jam /</li></ul>
</li>
</ol>
<ol type="a" start="3" class="mantra">
<li class="T">
ho;tAraM ratnadhA;tamam //
<ul><li class="L">
ho;tAram ratnadhA;tamam //</li></ul>
</li>
</ol>
</dd>
</div3>
</div2>
</dl>
</div1>
</div>
</body>
</html>

I'm surely missing the obvious, because with this stylesheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">
<xsl:output type="xml" indent="yes"/>
<xsl:template match="/">
<html>
	<body><xsl:apply-templates select="div" /></body>
</html>
</xsl:template>

<xsl:template match="div1//ul">
<xsl:copy-of select="parent::li"/>
</xsl:template>

<xsl:template mode="copy" match="*">
<xsl:copy>
<xsl:copy-of select="*|@*"/>
<xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

gave me:

<html>
<body>
</body>
</html>

WHile this one:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

<xsl:output type="xml" indent="yes"/>

<xsl:template match="/">
<xsl:copy-of select=".//preceding::ul"/>
</xsl:template>

<xsl:template mode="copy" match="*">
<xsl:copy>
<xsl:copy-of select="*|@*"/>
<xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>


Gives me only the "L" ones with no parent heirarchy:

<?xml version="1.0" encoding="utf-8"?>
<ul>
<li class="L">
agni;m ILe puro;hitam
</li>
<li class="L">
yajJa;sya deva;m Rtvi;jam /
</li>
</ul>

I freely welcome the revelation of the "obvious" I'm missing.


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


Current Thread