473,394 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

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
2 5135
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Duane Morin | last post by:
Subject says it all. Is XT still the fastest Java XSLT processor? The only benchmarks I can find seem old -- even the one on xml.com is from 2001. Duane
9
by: Jeff Rubard | last post by:
I am curious to know whether anyone has experience using XSLT for web XML (non-XHTML) styling, either with CSS or standalone. I myself have engaged in rather unsuccessful experiments with the...
3
by: Tim Dempsey | last post by:
Folks, I need some advice. I hpoe some of you can advise me. Our church's weekly bulletin has been published on paper for years. It is created in MS Word and sent to the publishing company....
7
by: Evan Stone | last post by:
Hello All, I was just curious to see if there was some analog to XSLT in WinForms. I'd like to be able to have my data be defined in XML, then process it with some kind of style...
2
by: gdevah | last post by:
Hi , I was looking for xslt to rearrang the order of attibutes within a node. xml to xml translation... <obj d="xslt" a="me" c="to" b="new"/> <prop c="it" b="does" a="how" d="matter"/> to
1
by: GiantCranesInDublin | last post by:
Hi, Has anyone used an XSLT to transform XML data into JSON format on the client before? If so, can they publish the XSLT style sheet? Cheers, GiantCranes
3
by: Luther Miller | last post by:
I am using an XSLT file to convert data in a DataSet to XMLSS format for opening in Excel. Excel doesn't like the way Dates in the DataSet are being ouput. It appears that a timezone offset is...
0
by: nospam | last post by:
I am looking for some feedback, experiences, or design patterns with respect to implementing a branding system (or at least a brandable web application) in ASP.NET. Some questions that arose in my...
1
by: yusuframp | last post by:
Using NetDataContractSerializer , I have produced a XML file whose source is given below. +++++++++++++++++++++++++++++++++++++ <Login xmlns:i="http://www.w3.org/2001/XMLSchema-instance"...
3
by: =?Utf-8?B?Q2h1Y2sgUA==?= | last post by:
I have some XML I want to display in a section of a web page. I want the XML displayed as a tree. The way you see XML if you load the file in the browser. It shows the tree and you can...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.