This is the day for the identity transform!
At 2008-10-10 18:00 +0000, Mati Hadi wrote:
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=â??wrapper[(_at_)class=â??menuâ??]>
<xsl:apply-templates select=*[not(descendant::wrapper[wrapper=â??menueâ??])]/>
</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.
You can do that by adding:
<xsl:template match="/">
<something>
<xsl:apply-templates/>
</something>
</xsl:template>
I hope this helps. (and that I've understood your requirement!)
. . . . . . . . . . . Ken
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>call xslt mati.xml mati.xsl mati.out
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>
</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>
</xsl:stylesheet>
t:\ftemp>rem Done!
--
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(_at_)CraneSoftwrights(_dot_)com
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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--