xsl-list
[Top] [All Lists]

Re: [xsl] Duplicate Elimination

2014-03-12 18:42:52
As suspected it was possible to avoid grouping. See the predicate
tacked on to B/Date.

Thanks all.

<xsl:apply-templates select="A/Date | B/Date[not(A/Date/text() = text())]>
   <xsl:sort select="." order="ascending"/>
</xsl:apply-templates>

On Wed, Mar 12, 2014 at 11:26 PM, Ihe Onwuka 
<ihe(_dot_)onwuka(_at_)gmail(_dot_)com> wrote:
Yes that did occur but grouping syntax is not something I retain in
short term memory so am going to try and avoid that...... we'll see.

On Wed, Mar 12, 2014 at 10:09 PM, Wendell Piez 
<wapiez(_at_)wendellpiez(_dot_)com> wrote:
Hi,

I hate to say it, but this is nicely handled as a grouping problem:

<xsl:for-each-group select="(A|B)/Date" group-by=".">
  <xsl:apply-templates select=".'/> <!-- applies a template to the
first member of each group -->
  <!-- select="current-group()[1]" to be more explicit -->
</xsl:for-each-group>

Many grouping problems are hidden in plain sight. :-)

Cheers, Wendell



On Wed, Mar 12, 2014 at 5:14 PM, Martin Holmes <mholmes(_at_)uvic(_dot_)ca> 
wrote:
If the text content of the element is all you care about, you could do
something like this:

<xsl:variable name="distinctDates">
<xsl:for-each select="distinct-values(A/Date | B/Date)">
        <xsl:sort/>
        <Date><xsl:value-of select="."/></Date>
</xsl:for-each>
</xsl:variable>

<xsl:apply-templates select="$distinctDates/Date"/>




On 14-03-12 01:34 PM, Ihe Onwuka wrote:

I have Date elements coming from 2 different parents.

<A>
   <Date>blah</Date>
</A>

<B>
     <Date>blah</Date>
</B>

I am doing

<xsl:apply-templates select="A/Date | B/Date>
    <xsl:sort select="." order="ascending"/>
</xsl:apply-templates>

and

<xsl:template match="Date">
  etc
</xsl:template>

I have noticed that when A and B have a child element of the same date
the Date template gets fired on each occasion, whereas I only want it
fired once

I  thought the union operator in the apply-templates would have the
effect of  eliminating duplicates or aren't they duplicates if they
have the same content but come from different parents.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--
Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables
_____oo_________o_o___ooooo____ooooooo_^

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--