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

Re: Omitting node within For-Each in Merge

Subject: Re: Omitting node within For-Each in Merge
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Mon, 8 Dec 2003 06:50:28 +0100
merge xml nodes
"JCS" <subscriber@xxxxxxxxxxxxx> wrote in message
news:BBFA426C.1055%subscriber@xxxxxxxxxxxxxxxx
> Hi everyone,
>
> The answer to this problem may be as simple as finding my sunglasses
perched
> on my head, but I'm having trouble dealing with a simple concept. I've
> looked in the archives and around the net but have come up blank.
>
> I'm merging two documents and matching a common element with a variable.
But
> how do I exclude or omit redundant data?
>
> My XML document A:
> <level>
>     <level>10</level>
>     <data>foo</data>
>     <more_data>bar<more_data>
> </level>
>
> My XML document B:
>
> <row>
>     <level>10</level>
>     <foo_data>foodata</foo_data>
>     <bar_data>bar_data</bar_data>
> </row>
>
> Output desired:
>
> <merge>
>     <level>10</level>
>     <data>foo</data>
>     <more_data>bar<more_data>
>     <foo_data>foodata</foo_data>
>     <bar_data>bar_data</bar_data>level>10>
> </merge>
>
>
> My current XSL:
>
> <xsl:variable name="merge" select="document('merge.xml')"/>
>
> <xsl:template match="/">
>
> <merge>
>     <xsl:for-each select="//level/level">
>         <xsl:variable name="level">
>             <xsl:value-of select="text()"/>
>         </xsl:variable>
>         <xsl:copy-of select="../child::*"/>
>         <xsl:copy-of select="$merge//row[Level=$level]/*"/>
>     </xsl:for-each>
> </merge>
>
> Because I'm asking it to select all the children of <row> I get the
<level>
> element output again, I want to omit this. Is there a special way to
> filter/omit nodes without suppressing the output with templates? i.e.
> Specify to select all children nodes EXCEPT <level>? This is where I get
> stuck for some reason.

Yes, instead of:

>         <xsl:copy-of select="$merge//row[Level=$level]/*"/>

use:

         <xsl:copy-of
select="$merge//row[level=$level]/*[not(self::level)]"/>

In the above xsl instruction you have one additional error -- there isn't
any "Level" element in the code you showed us -- should be "level".



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




 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.