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

Re: select descendant problem

Subject: Re: select descendant problem
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 10 Oct 2008 14:09:56 -0400
Re:  select descendant problem
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=bwrapper[@class=bmenub]>
<xsl:apply-templates
select=*[not(descendant::wrapper[wrapper=bmenueb])]/>
</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@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

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.