473,408 Members | 2,477 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,408 software developers and data experts.

Grouping and selecting Distinct items

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

XSLT:
[HTML]
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet 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="ascending" 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.SelectedValue + "']/Path[/HTML]

Finally,

Grab distinct values of Path:

[HTML]/Root/Book[not(Path=preceding-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>Exchange Hosted Services (EHS)</Value>
</Product>
<Path>
<Value>Build Skills</Value>
</Path>
<Audience>Implementer</Audience>
</Book>
<Book>
<ID>3</ID>
<Title>Two</Title>
<Product>
<Value>Exchange Server 2007</Value>
</Product>
<Path>
<Value>Build Skills</Value>
</Path>
<Audience>Implementer</Audience>
</Book>
<Book>
<ID>3</ID>
<Title>Three</Title>
<Product>
<Value>Exchange Server 2007</Value>
</Product>
<Path>
<Value>All</Value>
</Path>
<Audience>Sales</Audience>
</Book>
</Root>[/HTML]


Thank you in advance!
May 22 '07 #1
3 1759
dorinbogdan
839 Expert 512MB
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
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.SelectedValue + "']/Path

and

/Root/Book[not(Path=preceding-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 Expert 512MB
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
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...
4
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...
6
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"/>...
0
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...
2
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...
3
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...
11
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...
4
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.