[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Preserve ancestors/discard children
Can you solve it with something like this approach: <?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="*|@*|text()"> <xsl:if test="./ul/li[not(@class='L')] or not(name()='ul')"> <xsl:copy> <xsl:apply-templates select="*|@*|text()"/> </xsl:copy> </xsl:if> </xsl:template> </xsl:stylesheet> ? I.e., perform an identity transform, but look ahead at UL's to see if they have an LI with a CLASS attribute that is not 'L'. If they meet that criterion, or the current node is not a UL, go ahead and process it. My sense is that what you are missing is what is normally the easiest way to go about things in XSL, which is not to try to control everything, but instead just to sit back and let the template-evaluation sequence over the tree do the work for you. Steve John Robert Gardner wrote: > > 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 -- ---------------------------------------------------------------------- Steve Tinney Babylonian Section * University of Pennsylvania Museum stinney@xxxxxxxxxxxxx Phila, PA. 215-898-4047 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|