xsl-list
[Top] [All Lists]

Re: [xsl] Keys with duplicates should be simple

2014-01-31 11:21:05
I love except.

Cheers,

E.
-- 
Eliot Kimber
Senior Solutions Architect
"Bringing Strategy, Content, and Technology Together"
Main: 512.554.9368
www.reallysi.com
www.rsuitecms.com




On 1/31/14, 11:16 AM, "Wendell Piez" <wapiez@wendellpiez.com> wrote:

Hi,

I think the big difference here is the scope of inspection of 'a'
children.

<xsl:copy-of select="a[key('person',@href)[2]]"/>

Copies 'a' children as long as there is more than one node *anywhere
in the document* returned by the key for the a/@href.

It works like the exists() test because the effective Boolean value
for a sequence of nodes is true(), while for an empty sequence it's
false(). This corresponds the XPath 1.0 rule for coercing node sets to
Booleans, wherein (only) empty node sets become false().

Gerrit's suggestion using grouping (which I prefer) restricts the test
to duplicates among the 'a' element children of the parent being
matched.

For this, one could also say

a[@href = (../a except .)/@href]

... but we all know no one likes 'except' (except me) ... so the
grouping solution is less apt to mystify.

If one didn't want to see the first instance, only its duplicate(s), then

a[@href = preceding-sibling::a/@href]

Cheers, Wendell


On Fri, Jan 31, 2014 at 2:22 AM, Ihe Onwuka <ihe.onwuka@gmail.com> wrote:
No [2] means that a 2nd one exists which would be true if a 3rd one
existed etc.

The full dataset picks up instances where there is more than one
duplicate so I can verify the above interpretation.

Having said that your offering although more verbose is superior
semantically as really the best way to write this is something like
(and I am pleading the fifth on the syntax here)
exists(key('person',@href)[2]) but then you look at that and you
realise or can argue (I think) that what I wrote is an abbreviated
form of that anyway.

I suppose a guru could tell whether they are semantically identical
and whether the one abbreviates the other.

On Fri, Jan 31, 2014 at 12:45 AM, Graydon <graydon@marost.ca> wrote:
On Thu, Jan 30, 2014 at 04:38:49PM -0800, Dimitre Novatchev scripsit:
<xsl:key name="person" match="a" use="@href"/>
   <xsl:template match="person">
     <duplicate>
       <xsl:copy-of select="a[key('person',@href)[2]]"/>
     </duplicate>
   </xsl:template>
</xsl:stylesheet>

Can I note that the [2] would appear to suppose that there's only ever
one duplicate?

not(position() eq 1) is likely safer.

-- Graydon

--+AH4-------------------------------------------------------------------
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@lists.mulberrytech.com>
--+AH4---


--+AH4-------------------------------------------------------------------
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@lists.mulberrytech.com>
--+AH4---




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

--+AH4-------------------------------------------------------------------
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@lists.mulberrytech.com>
--+AH4---



--+AH4-------------------------------------------------------------------
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>
--+AH4---