[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: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 10 Oct 2008 20:21:39 +0100
RE:  select descendant problem
It rather depends on what you want to do with the nodes once you have
selected them. I suspect that you don't actually want to "select" them at
all: rather, you want to copy the part of the input tree that contains these
nodes, and not copy other parts. The way to do this is with a set of
template rules that processes (copies) the elements you are interested in,
and does something else with the others. Typically the default is to copy a
node:

<xsl:template match="*">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

and then you override this for nodes you want to process differently, for
example

<xsl:template match="wrapper">
  <xsl:apply-templates/>
</xsl:template>

which basically says "when you find an element, copy it and process its
children; but when you find a wrapper element, don't copy it, but still
process its children."

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: Mati Hadi [mailto:matilda.kapro@xxxxxxxx]
> Sent: 10 October 2008 19:00
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  select descendant problem
>
> Hi Mailinglist,
>
> I have an xml file like this:
> <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>
>
> 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[@class=menu]>
> <xsl:apply-templates
> select=*[not(descendant::wrapper[wrapper=menue])]/>
> </xsl:for-each>
> But this dos not work. Any ideas please
>
> Thank you in advance
> Matilda
>
>
>
>       __________________________________________________________
> Ger det lengsamt? Skaffa dig en snabbare bredbandsuppkoppling.
> Svk och jdmfvr priser hos Kelkoo.
> http://www.kelkoo.se/c-100015813-bredband.html?partnerId=96914325

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.