xslt: for-each group, grouping by child nodes?

J

jon|k

hi all--

i need to do a transformation that removes duplicates (among other
things). to accomplish that, i'm trying to use for-each-group, but it
doesn't work. i need to select for duplicates by looking at the child
node sequence (see sample below). note that when i do an xsl-message on
the group-by expression inside the for-each-group, it has exactly what
i'd like to group by listed, but i guess it doesn't like to have a
sequence of nodes in the group-by? (it repeats way too many times, and
i'm thinking it's because the expression in the group-by clause is a
sequence of attribute nodes and not converted to a string or something
that can be simply "eq"ed?)

<xsl:for-each-group select="(//sentence|//node)"
group-by="./child::*/(@cat|@pos)">
<xsl:apply-templates select="current-group()" />
</xsl:for-each-group>

here's sample data. i only want the template run ONCE for each
combination of sentence/node + the cat/pos attributes of the first
level children (e.g., only run for the nodes that i've starred
[although it could be any similar node; as long as it's just run
once]). note that i don't care what's two levels down, just what's on
the first level.

example:
<sentence id="1" *>
<node cat="A" *>
<word pos="E" />
<word pos="F" />
</node>
<node cat="D" * />
<word pos="B" />
</sentence>
<sentence id="2" *>
<node cat="A" * />
<node cat="D" />
</sentence>
<sentence id="3">
<node cat="A" />
<node cat="D" />
</sentence>

what am i doing wrong, or have i tried to tackle this completely
incorrectly? thanks in advance for any help you can give!

jon
 
J

jon|k

oops--contrary to my typo in the title, i'm using for-each-group, not
grouping by for-each :)

jon
 
J

jon|k

ok, in case anyone else is wondering, i've solved the problem by adding
[1] to the select attribute of apply-templates. i think that gives me
the results i want.

<xsl:for-each-group select="(//sentence|//node)"
group-by="./child::*/(@cat|@pos)">
<xsl:apply-templates select="current-group()[1]" />
</xsl:for-each-group>

jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top