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

Re: display parts of XML tree with xsl:copy ?

Subject: Re: [xsl] display parts of XML tree with xsl:copy ?
From: Robert Sösemann <robert.soesemann@xxxxxx>
Date: Tue, 26 Feb 2002 16:01:12 +0100
parts of a tree
Thanks a lot for your quick and helpful support.
There is just one question left.

In the moment I get all the volume and number elements incl. text()
even if they issue elem they belong to does not contain any article that
fullfils my condition.

See:
  <issue>
     <volume>17</volume>
     <number>1</number>     <-------------------- this whole <issue> should
not be in output
     <articles />
  </issue>
  <issue>
     <volume>17</volume>
     <number>2</number>
     <articles>
        <article>
         <title>Defining Data Types in a Database Language - A Proposal for
Adding Date and Time Support to SQL.</title>
         <initPage>53</initPage>
         <endPage>76</endPage>
          <authors>
             <author position="00">C. J. Date</author>
          </authors>
        </article>
     </articles>
</issue>
<issue>
...
---
How can I controll that only those ancestors are copied that are in an valid
articles supertree?

----- Original Message -----
From: "Jeni Tennison" <jeni@xxxxxxxxxxxxxxxx>
To: "Robert Sösemann" <robert.soesemann@xxxxxx>
Cc: <XSL-List@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Tuesday, February 26, 2002 12:09 PM
Subject: Re: [xsl] display parts of XML tree with xsl:copy ?


> Hi Robert,
>
> > From the following article DB (SigmodRecord) i want to e.g. only
> > articles by a certain author but the result tree should still
> > contain the information of <number> which is nearer to the root.
>
> The way I'd approach this kind of filtering problem is to create a
> basic stylesheet that performs the identity transformation (copies
> whatever you get in the source) as follows:
>
> <xsl:transform version="1.0"
>                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <!-- identity template -->
> <xsl:template match="node()|@*">
>   <xsl:copy>
>     <xsl:apply-templates select="@*|node()" />
>   </xsl:copy>
> </xsl:template>
>
> </xsl:transform>
>
> Then, to that identity transform you can add templates that filter out
> portions of the source document. For example, to get basically the
> same thing as the source document, but only include articles that have
> Karen Botnich as an author, I'd use:
>
> <xsl:transform version="1.0"
>                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <!-- identity template -->
> <xsl:template match="node()|@*">
>   <xsl:copy>
>     <xsl:apply-templates select="@*|node()" />
>   </xsl:copy>
> </xsl:template>
>
> <xsl:template match="articles">
>   <articles>
>     <xsl:apply-templates
>       select="article[authors/author = 'Karen Botnich']" />
>   </articles>
> </xsl:template>
>
> </xsl:transform>
>
> Since you want to copy the whole of such articles, you could use
> xsl:copy-of instead:
>
> <xsl:template match="articles">
>   <articles>
>     <xsl:copy-of
>       select="article[authors/author = 'Karen Botnich']" />
>   </articles>
> </xsl:template>
>
> That's likely to be slightly faster.
>
> If you're more comfortable with a pull method, you could use the
> stylesheet instead:
>
> <xsl:transform version="1.0"
>                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:template match="/">
>   <issues>
>     <xsl:for-each select="/issues/issue">
>       <issue>
>         <xsl:copy-of select="volume | number" />
>         <articles>
>           <xsl:copy-of
>             select="articles/article[authors/author = 'Karen Botnich']" />
>         </articles>
>       </issue>
>     </xsl:for-each>
>   </issues>
> </xsl:template>
>
> </xsl:transform>
>
>
> Cheers,
>
> Jeni
>
> ---
> Jeni Tennison
> http://www.jenitennison.com/
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.