Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


cascading deletion/copy in xsl

From: tschwartz@-----------.---
To: NULL
Date: 1/4/2007 2:41:00 PM

I have an xml document in which elements are hierarchically related to
eachother conceptually.  Unfortunately, the hierarchical relationship
is not modelled in the schema (i.e., the elements are "flattened" in
the document".  I have a case in which I want to remove a high level
element using xslt and want all the related lower-level elements to be
removed as well. Is there an easy way to do this in a template?

For example, imagine a relationship of elements describing animals
starting with "animal" at the top of the hierarchy and ending in "pets"
at the bottom:

animal => class => beastie => breed => pet

Given the xml below, say I wanted to remove the class named "Aves" and
wanted  to cause a cascading removal of all other elements related to
"Aves".  Is there a simple way to do this using xsl that helps me avoid
writing specific templates for each child node of "animals"?

<?xml version="1.0" encoding="utf-8"?>
<animals>

   <classes>
      <class name="Mammalia"/>
      <class name="Aves"/>
   </classes>

   <beasties>
      <beast type="cat" class="Mammalia"/>
      <beast type="dog" class="Mammalia"/>
      <beast type="bird" class="Aves"/>
   </beasties>

   <breeds>
      <breed name="collie" type="dog"/>
      <breed name="beagle" type="dog"/>
      <breed name="persian" type="cat"/>
      <breed name="siamese" type="cat"/>
      <breed name="parakeet" type="bird"/>
      <breed name="crow" type="bird"/>
   </breeds>

   <pets>
      <pet name="rover" breed="collie"/>
      <pet name="fluffy" breed="persian"/>
      <pet name="tweety" breed="parakeet"/>
   </pets>

</animals>

The desired xml output would be this:

<?xml version="1.0" encoding="utf-8"?>
<animals>

   <classes>
      <class name="Mammalia"/>
   </classes>

   <beasties>
      <beast type="cat" class="Mammalia"/>
      <beast type="dog" class="Mammalia"/>
   </beasties>

   <breeds>
      <breed name="collie" type="dog"/>
      <breed name="beagle" type="dog"/>
      <breed name="persian" type="cat"/>
      <breed name="siamese" type="cat"/>
   </breeds>

   <pets>
      <pet name="rover" breed="collie"/>
      <pet name="fluffy" breed="persian"/>
   </pets>

</animals>



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent