[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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)
robert gardner missing
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.