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

Re: Removal of similar but different elements from XML

Subject: Re: Removal of similar but different elements from XML file
From: "Mark Wilson" <mark@xxxxxxxxxxxx>
Date: Fri, 6 Mar 2009 10:10:22 -0700
Re:  Removal of similar but different elements from XML
Close enough for me to work forward with it (not always a preceding-sibling::Subject[Heading]), may simply be a sibling::).

Thank you so much!
Mark

--------------------------------------------------
From: "Martin Honnen" <Martin.Honnen@xxxxxx>
Sent: Friday, March 06, 2009 10:00 AM
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re:  Removal of similar but different elements from XML file

Mark Wilson wrote:
In an XML file used to generate a cumulative index to a journal, I have a number of similar citations, one of which sometimes needs to be removed from the file.

As shown in the original example below, note that the content of the first <Subject>'s <SubDiv1> child, Kucera, Vaclav, matches the content of the second <Subject><Heading>'s child, Kucera, Vaclav. As shown in the output example, I want to remove this second <Subject>.

However, I only want to do this for certain <Headings> and need to specify in my XSLT style sheet, for instance, if within an <Item> the <Heading>Stamp Designers</Heading>'s <SubDiv1> child is identical to another another <Subject>'s <Heading> child, remove the latter. Thus, I cannot use a generalized version (I must be able to specify the first <Heading>, because not all of these constructs should be removed). I do not object to running the style sheet repeatedly to apply it to, for instance, <Heading>Stamp Engravers</Heading>. However, it would be great to be able to drive it with a list like:

<Removals>
   <Citation>Stamp Designers</Citations>
   <Citation>Stamp Engravers</Citations>
<Removals>

Any hints or help would be greatly appreciated.

Here is a stylesheet that tries to implement your rules as far as I have understood them:


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:data="http://example.com/2009/data"
  exclude-result-prefixes="data"
  version="1.0">

<xsl:output method="xml"/>

  <data:data>
    <Removals>
       <Citation>Stamp Designers</Citation>
       <Citation>Stamp Engravers</Citation>
    </Removals>
  </data:data>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

<xsl:template match="Subject[Heading = preceding-sibling::Subject[Heading = document('')/xsl:stylesheet/data:data/Removals/Citation]/SubDiv1]"/>

</xsl:stylesheet>

It is simply the identity transformation plus one template suppressing the copying of any Subject elements for which there is a preceding Subject element where the Heading is in the Removals list and where the preceding SubDiv1 is equal to the Heading.

--

Martin Honnen
http://JavaScript.FAQTs.com/

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.