Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] not copying duplicate node to the output (remove duplicate node)

From: "Wei Chin" <wei_chin@----------->
To:
Date: 3/3/2007 6:11:00 PM
Hi Mukul,



Thank you so very much for your kind help! The code you wrote worked 
perfectly.



There is one issue, however, the file I am running is kinda large, it has 
8000 lines before the processing, group A and B combined. So each time when 
I run the code using small amount of data, it worked just perfectly.  
Whenever I run this code against the real file, which is 8000 lines, the 
XMLSpy just freezes. Is there any insight about this?



Thank you again and I really appreciate your kindness helping out, this 
really means a lot to me!




Best Regards,



Wei Chin








----Original Message Follows----

From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>

Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx

To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx

Subject: Re: [xsl] not copying duplicate node to the output (remove 
duplicate node)

Date: Fri, 2 Mar 2007 21:44:09 +0530



I think you have taken the right approach to use the identity template 
pattern.



I have tried to understand your requirement, and come up with this solution:



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">



<xsl:output method="xml" indent="yes"/>



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

<xsl:template match="release[@display_on = 'headlines;'][doc_number =
../release[not(@display_on = 'headlines;')]/doc_number]" />

<xsl:template match="release[@display_on =
'headlines;'][normalize-space(doc_number) = '']">
  <xsl:copy-of select="." />
</xsl:template>

<xsl:template match="@display_on[not(. = 'headlines;')]">
  <xsl:attribute name="display_on">
    <xsl:value-of select="concat(., ';headlines')" />
  </xsl:attribute>
</xsl:template>

</xsl:stylesheet>



I hope this helps.



On 3/2/07, Wei Chin <wei_chin@xxxxxxxxxxx> wrote:
Hi I have this problem:
I need to combine two data groups below:
A. conditions:
1. Each release has a unique Id.
2. The two groups have duplicated <doc_number>s. if one <release> in data
group A has a <doc_number> that is already in data group B, remove that
entire <release> node in data group A.
3. Certain <release> does not even have a <doc_number>, but there is a
<doc_number /> tag to represent an empty value. in this case, we keep the
entire <release> node.
4. insert ";headlines;" into the "display_on" attribute to the <release>.
Current file:
<!-- start of file -->
<releases>
<!-- Data group A -->
<release id="2" name="AB" display_on="headlines;" type="NEWS">
 <doc_number>6</doc_number>
</release>
<release id="4" name="CD" display_on="headlines;" type="NOTICE">
 <doc_number>5</doc_number>
</release>
<release id="6" name="EF" display_on="headlines;" type="ORDER">
 <doc_number>4</doc_number>
</release>
<release id="8" name="GH" display_on="headlines;" type="ORDER">
 <doc_number>3</doc_number>
</release>
<release id="10" name="IJ" display_on="headlines;" type="NOTICE">
 <doc_number>2</doc_number>
</release>
<release id="12" name="KL" display_on="headlines;" type="NOTICE">
 <doc_number />
</release>

<!-- Data group B -->
<release id="14" name="XY" display_on="homepage" type="MEMORANDUM">
 <doc_number>5</doc_number>
</release>
<release id="16" name="MN" display_on="sidepage" type="NOTICE">
 <doc_number>4</doc_number>
</release>
<release id="18" name="OP" display_on="otherpage" type="NOTICE">
 <doc_number>3</doc_number>
</release>
</releases>
<!-- end of file -->
Desired resulting file:
<!-- start of file -->
<releases>
<!-- Data group A -->
<release id="2" name="AB" display_on="headlines;" type="NEWS">
 <doc_number>6</doc_number>
</release>
<release id="10" name="IJ" display_on="headlines;" type="NOTICE">
 <doc_number>2</doc_number>
</release>
<release id="12" name="KL" display_on="headlines;" type="NOTICE">
 <doc_number />
</release>

<!-- Data group B -->

<release id="14" name="XY" display_on="homepage;headlines"

type="MEMORANDUM">

 <doc_number>5</doc_number>

</release>

<release id="16" name="MN" display_on="sidepage;headlines" type="NOTICE">

 <doc_number>4</doc_number>

</release>

<release id="18" name="OP" display_on="otherpage;headlines" type="NOTICE">

 <doc_number>3</doc_number>

</release>

</releases>

<!-- end of file -->

Right now I have this code written to generate the result, but it only 
works

partially.

1. It removes the duplicated <doc_number> from each release, but it does 
not

remove the whole release.

2. It does not insert ";headlines;" into the "display_on" attribute to the

<release>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

version="1.0">

<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:template match="doc_number">

 <xsl:if test="not(string(.))">



 </xsl:if>
 <xsl:if test="not(. = following::fcc_doc_number)">
  <xsl:copy>
   <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
 </xsl:if>
</xsl:template>
<xsl:template match="@*|node()">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()"/>
 </xsl:copy>
</xsl:template>
</xsl:stylesheet>
Please anyone help out? thank you!




--
Regards,
Mukul Gandhi

_________________________________________________________________

Dont miss your chance to WIN 10 hours of private jet travel from Microsoft. 
Office Live http://clk.atdmt.com/MRT/go/mcrssaub0540002499mrt/direct/01/


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