By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,614 Members | 1,620 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,614 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Jan 19 '06 #1
Share this Question
Share on Google+
2 Replies


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

jon

jon|k wrote:
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


Jan 19 '06 #2

P: n/a
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

jon|k wrote:
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


Jan 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.