RE: [xsl] Delete XML Node

Subject: RE: [xsl] Delete XML Node
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 01 Nov 2002 11:29:12 -0500
Deepak,

At 09:32 AM 11/1/2002, you wrote:
Thank you very much. Your solution works perfectly fine. But looking at a maintenance point of view, the rule for <B> and <C> are repeated twice, once for <Y> and once of either <B> or <C>. If there is a change to any of the rules for <B> or <C>, I would have to remember to change two places instead of just one. Do you think there is a way to avoid this?

Yes, that issue is what I was referring to when I said


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.

This is because the test on the Y is really "do I need a Y (because lower down I'm going to have a B or C child)", whereas the test on B is really "do I need *this* B". If you know you don't need the second test you can leave it out.

What the best solution is in your actual case will depend on exactly what your data and rules really are. It's a bit more complicated because you have more than one element you want to filter.

Cheers,
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