473,698 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Grouping and selecting Distinct items

2 New Member
I have created an xslt that sorts the following xml on node: Path

XSLT:
[HTML]
<?xml version="1.0" encoding="utf-8"?>
<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="Root">
<Root>
<xsl:for-each select="./*">
<xsl:sort select="./Path" order="ascendin g" data-type="text"/>
<xsl:copy-of select="." />
</xsl:for-each>
</Root>
</xsl:template>

<xsl:template match="Book">
<xsl:copy-of select="." />
</xsl:template>

<xsl:template match="*">
<xsl:copy-of select="." />
</xsl:template>

</xsl:stylesheet>
[/HTML]

I would like to next grab node Path where Audience equals a value passed unto it:

[HTML]/Root/Book[Audience='" + selection.Selec tedValue + "']/Path[/HTML]

Finally,

Grab distinct values of Path:

[HTML]/Root/Book[not(Path=preced ing-sibling::Book/Path)]/Path[/HTML]

Is there a way to incorporate these last two XPath's onto my XSLT?

A sample of my XML:
[HTML]
<Root>
<Book>
<ID>85</ID>
<Title>One</Title>
<Product>
<Value>Exchan ge Hosted Services (EHS)</Value>
</Product>
<Path>
<Value>Build Skills</Value>
</Path>
<Audience>Imple menter</Audience>
</Book>
<Book>
<ID>3</ID>
<Title>Two</Title>
<Product>
<Value>Exchan ge Server 2007</Value>
</Product>
<Path>
<Value>Build Skills</Value>
</Path>
<Audience>Imple menter</Audience>
</Book>
<Book>
<ID>3</ID>
<Title>Three</Title>
<Product>
<Value>Exchan ge Server 2007</Value>
</Product>
<Path>
<Value>All</Value>
</Path>
<Audience>Sales </Audience>
</Book>
</Root>[/HTML]


Thank you in advance!
May 22 '07 #1
3 1781
dorinbogdan
839 Recognized Expert Contributor
Welcome to TheScripts TSDN....

It may require to use xsl:param passed from code onto XSL.
If coding for C#, see this link.
For Javascript, see this link.
May 22 '07 #2
Mchine34
2 New Member
Thanks for your recommendations dorinbogdan. I'm doing this using C#. I really liked the link you sent "If coding for C#".

The reason I posted this question is because I'm having trouble doing this in C# alone. By this I mean:

/Root/Book[Audience='" + selection.Selec tedValue + "']/Path

and

/Root/Book[not(Path=preced ing-sibling::Book/Path)]/Path

in 1 XPath expression.

I figured this can be done easier using XSLT. Would you agree with this?

Thanks.
May 22 '07 #3
dorinbogdan
839 Recognized Expert Contributor
Yes it's easier, and the XPath syntax is the same, you can use the same XPath expression, just replace the C# variable with the XSL param within the XSL template.
See this reference for XPath syntax.
Also it's helpful to have an overview over this XSL tutorial.
May 23 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2425
by: Kevin Brown | last post by:
Is there anyway to generate this type of resulting HTML table from this XML using XSLT? Basically I need to be able to consult 2 trees of data to generate the HTML, but I have not been able to figure out how to do so. There is supposed to be a way of using templates and the key function to do grouping, but can it be done with 2 different trees? If so, are there any examples of such things Thanks for any help, Kevin
4
3565
by: kristofera | last post by:
I am trying to do a distinct grouping of some nodes sorted by a numeric value but for some reason the distinct (preceding-sibling filter) is applied to the result as if not sorted. If I don't use the preceding-sibling filter, the nodes are properly sorted. Is this a bug in the xslt processor I'm using (.net framework 1.1) or is this correct behaviour? Any alternative solutions that will show me the lowest priced item in each category?...
6
1579
by: Per Jørgen Vigdal | last post by:
I have a XML that I need to map. The XML goes like: <Children> <Child> <References> <External> <Reference name="filename" value="1.dat"/> <Reference name="invoicenr" value="1111111"/> <Reference name="invoicer_name" value="Bill"/>
0
1088
by: Andreas Håkansson | last post by:
I've been using the Muenchian method to group XML data, however I have run into a situation where I am unsure how to solve it. What I need to do is select distinct groups of items. I have an XML dokument which looks like the one below, where I have 1-n item nodes and each item node can have 2-n detail nodes. The group node can have a value of either one or two, nothing else. <items> <item>
2
1700
by: Andreas Håkansson | last post by:
Seeing how my previous post seem to have fallen between the cracks, I thought I would have a second, more direct, go at it. So my question is "Is it possible to group (Muenchian method) over multiple nodes?" I will use an example to try to explain what I need to do and what I have for data. The example might not be very realistic but it's much easier than to try and explain using the scenario I have =P Suppose I had a list of...
3
2735
by: ahaque38 | last post by:
Hello. Using A2K SP3, I am having the following problem with a report using "Sorting and Grouping". I have recently added a grouping in the reports for "Category2<>'CONTRACTS'". I have reports at the plan (overall totals), department and division levels which have sorting and grouping implemented with this new
11
3447
by: Ron L | last post by:
I have a data table that lists a series of items in my database. In my user form, I want the user to be able to filter by a number of criteria (e.g. location, contract, date modified, etc). Other than modified date, all my filters are selected via combo boxes. I would like to have the combo boxes update so that if there are no items available in the currently filtered list for a given selection, that selection will not appear in the...
4
6144
by: monomaniac21 | last post by:
hi! is it possible to do the aforementioned query - selecting only distinct in 1 col but retrieving all other cols at the same time. regards marc
3
6804
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
In Visual Studio 2005, I have my DataSet filled with several static tables (they might get changed weekly, but that's about it). With one of these tables in the DataSet, is it possible to select distinct items? Ex: I want to fill a tree with a list of job titles, and the Employee table isalready filled with all of our employee records. Is there a way I could do something like this below?
0
8678
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9030
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.