|
Subject: RE: [xsl] How to make this XSLT works for more than two section From: Robby Pelssers <Robby.Pelssers@xxxxxxx> Date: Fri, 15 Jun 2012 17:43:58 +0200 |
Try this one... added a few functions to ease the pain:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:custom="www.company.com">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:function name="custom:equalPredecingItemCount" as="xs:integer">
<xsl:param name="preceding_items"/>
<xsl:param name="this_item"/>
<xsl:value-of select="sum(for $item in $preceding_items return
custom:getEqualityValue($item, $this_item))"/>
</xsl:function>
<xsl:function name="custom:getEqualityValue" as="xs:integer">
<xsl:param name="item1"/>
<xsl:param name="item2"/>
<xsl:value-of select="if (deep-equal($item1, $item2)) then 1 else 0"/>
</xsl:function>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!-- we skip the item if it has at least 1 equal preceding item -->
<xsl:template
match="item1[custom:equalPredecingItemCount(preceding::item1, .) > 0]"/>
</xsl:stylesheet>
-----Original Message-----
From: Wolfgang Laun [mailto:wolfgang.laun@xxxxxxxxx]
Sent: Wednesday, June 13, 2012 2:43 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] How to make this XSLT works for more than two section
I find that I get the desired output, except for the last item1, which
is also removed, but that has a matching predecessor, i.e., the second
item1 in the output.
-W
On 13/06/2012, Jo Na <jkoe888@xxxxxxxxx> wrote:
> And desired Output:
> <myroot>
> <RNC>
> <nodeA id="a">
> <section id="i">
> <item1 id="0" method="delete"/>
> <item1 id="1" method="create">
> <otherchild>a</otherchild>
> </item1>
> </section>
> <section id="i">
> <item1 id="0" method="delete"> <!-- third consecutive
> delete BUT children have different value , so we don't remove this -->
> <somechild>bbb</somechild>
> </item1>
> <item1 id="3" method="create">
> <other>xx</other>
> </item1>
> <item1 id="0" method="create">
> <otherchild>a</otherchild>
> </item1>
> </section>
> <section id="i">
> <item1 id="1" method="create">
> <otherchild>a</otherchild>
> </item1>
> </section>
> </nodeA>
> </RNC>
> </myroot>
>
> How to fix the XSLT to apply to more than two sections with the same
> id as shown on the example. (right now the algorithm works fine for
> only two sections with the same id)
>
> The objective is to remove node with successive duplicate with the
> same element name item1 item2 etc, same id and same method.
> An XML node followed by other node with exact same element name, same
> id, same method and same children will be considered duplicate.
> if the two nodes being compared did not share the same 'nodeA' level
> node, then they should not be considered as duplicates to be removed
>
> Thank you.
> Jo
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] How to make this XSLT wor, Wolfgang Laun | Thread | Re: [xsl] How to make this XSLT wor, Andrew Welch |
| Re: [xsl] shortest way to write thi, henry human | Date | Re: [xsl] How to make this XSLT wor, Andrew Welch |
| Month |