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

RE: Delete XML Node

Subject: RE: Delete XML Node
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 31 Oct 2002 17:12:52 -0500
removing xml node
Deepak,

Given mapping rules like this, a template-based approach is *way* easier:

At 04:57 PM 10/31/2002, you wrote:
Input XML Output XML

<X> maps to----> <X1>

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

<A>A</A> maps to----> <A1>A</A>

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

 <Y>             maps to--->               <Y1>
                 if resultant <Y1>
                 has got elements within it

I'm translating this into "maps to Y1 if the source Y contains a B with value "ABC" or a C with value "XYZ". This re-expression is necessary since you can inspect the source tree, but the result tree doesn't exist yet so you can't test the "resultant Y1":


<xsl:template match="Y">
  <xsl:if test="B[.='ABC'] or C[.='XYZ']">
    <Y1>
      <xsl:apply-templates/>
    </Y1>
  </xsl:if>
</xsl:template>

   <B>B</B>      maps to---->                 <B1>B1</B1>
                 only if data contained
                 in <B> is "ABC"

<xsl:template match="B"> <xsl:if test=". ='ABC'"> <B1> <xsl:apply-templates/> </B1> </xsl:if> </xsl:template>

Or more simply, if a Y will never have more than one B, you can do

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

(Since you'll never even get to the B if the Y test was not passed, it's safe to just process it.)

   <C>C</C>      maps to---->                 <C1>C1</C1>
                 only if data contained
                 in <C> is "XYZ"

like B, with appropriate adjustments


  </Y>                                      </Y1>
</X>                                         </X>

According to the mapping rules for <B> and <C> the output XML should not contain <B1> and <C1> and thus <Y1> would be empty. But <Y1> should appear in the output only if <B1> or <C1> is present.

Put all these templates together in a stylesheet and try it out....


I hope this helps,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


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.