Subject: Re: [xsl] select descendant problem From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 10 Oct 2008 14:09:56 -0400 |
select=*[not(descendant::wrapper[wrapper=bmenueb])]/>I have an xml file like this: ... I want to select all the children of the wrapper, except the children wrappers. I mean I want to select i.e from the first wrapper just title, section,section/title, section/table and section/section,but not the child wrapper, and from the child wrapper, I want to select all its children except the child wrapper, and so on. I tried to write : <xsl: for-each select=bwrapper[@class=bmenub]> <xsl:apply-templates
</xsl:for-each> But this dos not work.
Yes, you are trying a "pull" approach and it isn't going to help you. By pushing your data through template rules you'll have the opportunity to act on wrapper elements by only processing their children without actually adding them to the result.
Now, note that the result *isn't* well-formed XML but it is a well-formed external parsed general entity. You have more than one top element in the result ... so to make this a document you'll have to wrap it in something.
<xsl:template match="/"> <something> <xsl:apply-templates/> </something> </xsl:template>
t:\ftemp>type mati.xml <wrapper class="menu"> <title>menu1</title> <section> <title>Indoor climate</title> <table> some table here</table> <section> <title> under menus</title> <paragraph>some text here</paragraph> </section> <wrapper class="menu"> <title>menu1.1</title> <section> <title>Temperatur</title> <paragraph>some text here</paragraph> </section> <wrapper class="menu"> <title>menu1.1.1</title> <section> <title>Heat</title> <paragraph>some text here</paragraph> </section> <wrapper class="menu"> <title>menu1.1.1.1</title> <section> <title>Heat2</title> <paragraph>some text here</paragraph> </section> </wrapper> </wrapper> </wrapper> </section> </wrapper>
t:\ftemp>type mati.out <?xml version="1.0" encoding="utf-8"?> <title>menu1</title> <section> <title>Indoor climate</title> <table> some table here</table> <section> <title> under menus</title> <paragraph>some text here</paragraph> </section>
<title>menu1.1</title> <section> <title>Temperatur</title> <paragraph>some text here</paragraph> </section>
<title>menu1.1.1</title> <section> <title>Heat</title> <paragraph>some text here</paragraph> </section>
<title>menu1.1.1.1</title> <section> <title>Heat2</title> <paragraph>some text here</paragraph> </section>
t:\ftemp>type mati.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="@*|node()"><!--identity for all other nodes--> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
<xsl:template match="wrapper"> <xsl:apply-templates/> </xsl:template>
-- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video sample lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg Video course overview: http://www.youtube.com/watch?v=VTiodiij6gE G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] select descendant problem, Mati Hadi | Thread | RE: [xsl] select descendant problem, Michael Kay |
[xsl] select descendant problem, Mati Hadi | Date | RE: [xsl] select descendant problem, Michael Kay |
Month |