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 1 3374
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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">...
|
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...
|
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...
|
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
|
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...
|
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...
|
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............
|
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"...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| |