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

Problems getting xsl:key to work....

Folks,

I'm struggling with XSLT key's and stuff.... anybody out there who
*REALLY* understands this stuff???

Okay, my XML file looks something like this (partially):

<?xml version="1.0" encoding="ISO-8859-1"?>
<report>
<meta>
<structure>
<title seq="4" text="Foo" />
<title seq="5" text="Bar" />
<title seq="6" text="Widgets" />
<title seq="16" text="Foo" />
<title seq="17" text="Bar" />
</structure>
</meta>
</report>

What I'd like to achieve is to get a list of comma-separated values of
the "text" attribute, with each entry showing up only once, and
alphabetically sorted, something like:

Defined texts: Bar, Foo, Widgets

I tried to define a xsl:key that would help me achieve this - no luck
so far. I had a sample, but that was based on a XML element, rather
than an attribute - and I just can't seem to make the transition!

So here's my XSL definition of the key:

<xsl:key name="distinct" match="title" use="@text" />

so I was thinking this will keep a list of unique "text" attributes,
no?

I wanted to output the list from my XSL with this fragment:

<xsl:for-each
select="report/meta/structure/title[generate-id()=generate-id(key('distinct',
..))]">
<xsl:sort select="@title" />
<xsl:value-of select="@text">

<xsl:if test="position() != last()">, </xsl:if>
</xsl:for-each>

The extra clause in the xsl:for-each is the one I grabbed from a
sample, based on a XML element being used (rather than the attribute).

I just can't seem to make it work, no matter how I try to change
around the xsl:key and the xsl:for-each clauses.....

Any takers? It's probably really stupid, once you know how to do it -
but I just can't seem to crack this one!!

Any help is highly appreciated !!

Thanks
Marc

================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Nov 12 '05 #1
1 3375
Marc Scheuner [MVP ADSI] wrote:
I'm struggling with XSLT key's and stuff.... anybody out there who
*REALLY* understands this stuff???
Basically keys in XSLT are extremely simple. Just think of xsl:key as a
hashtable, where use attribute defines hashtable key and match attribute
defines value. Once defined, you can get values by keys.

I tried to define a xsl:key that would help me achieve this - no luck
so far. I had a sample, but that was based on a XML element, rather
than an attribute - and I just can't seem to make the transition!

So here's my XSL definition of the key:

<xsl:key name="distinct" match="title" use="@text" />

so I was thinking this will keep a list of unique "text" attributes,
no?

I wanted to output the list from my XSL with this fragment:

<xsl:for-each
select="report/meta/structure/title[generate-id()=generate-id(key('distinct',
.))]">


key('distinct', .) returns all stored values in "hahstable" (aka nodes
in xsl:key), by key, which is . - string value of title element, what is
obviously wrong, because your xsl:key defines text attribute value as
key (use="@text"). Try instead
<xsl:for-each
select="report/meta/structure/title[generate-id()=generate-id(key('distinct',@text))]">
--
Oleg Tkachenko
XmlInsider
http://blog.tkachenko.com
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Darren Gilroy | last post by:
I was wondering if there was a way to cache a built xsl:key? I have a custom resolver that returns a DOM when "document('Assets.xml')" is requested, but the stylesheet takes some amount of time...
0
by: Stefan Slapeta | last post by:
Hi, I would to like to have a schema for the following structure in XML and have no idea how to achieve this: <root_element> <!-- included from file one --> <container name="A">...
1
by: Vishnu | last post by:
Hi group I googled for this information first,but the results i got were a bit outdated(2002 results).I just want to make sure whether its still the case. My question is:does Embedded XSL...
3
by: bjam | last post by:
Help! The apply-templates function is not currently allowing me to select a specific template... eventhough I tried putting a select statement, it does not seem to work??? Can someone help show...
1
by: Srinvias Vikram | last post by:
hai, how can we get Work Sheet in Excel and can place it in Word Document through C# progrmming, if any solution please give me Reply,I really Appreciate your help. Regards, srinvias vikram
0
by: Nadav | last post by:
Hi, I am writing a VS.NET AddIn, I wish to get key-stroke events from the IDE e.g. F5, CTRL+F2, ... I didn't find any method/event that provide this kind of functionality... How can I get...
3
by: Jerry | last post by:
Hello, I have put a simple form together with a lable and a textbox. I want to be able to trap the ENTER key when is pressed. So I can check the texted enetered. If correct, call up the main...
1
by: atul123456789 | last post by:
Hi can i get key corresponding to a particular value in hashtable in java. we can get value corresponding to particular key but if we want to get key corresponding to particular value............
0
by: Leira | last post by:
Hi, I have a problem with grouping. My source XML has <record> elements that have a @name and a @group attribute. It looks something like this: <root> <result> <record name="test1"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
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,...
0
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...

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.