xsl-list
[Top] [All Lists]

RE: Delete XML Node

2002-11-01 09:39:15
Deepak,

At 11:29 AM 11/1/2002, I wrote:
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>

This allows your rule (finding that you need a Y since you have a B='ABC') to be in one place, which is better; the down side is that if you have input like

<Y>
  <B>ABC</B>
  <B>LMN</B>
  <C>zzz</C>
<Y>

And your rules are only in the Y template, since "B[.='ABC'] or C[.='XYZ']" is true, all B and C elements will be processed.

Of course the simpler solution to this (doh!) is:

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

or the analogous logic. Then you need no logic in the B template.

Incidentally, this can be further compressed (if you like) as:

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

<xsl:template match="Y"/> <!-- this suppresses a Y unless it matches the other template -->

Cheers,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
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



<Prev in Thread] Current Thread [Next in Thread>