[xml] XSLT question
- From: Colin Fox <cfox cfconsulting ca>
- To: xml gnome org
- Subject: [xml] XSLT question
- Date: Mon, 11 Apr 2005 14:40:10 -0700
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I've got a question about XSLT and libxslt.
Assuming an XML file that looks like this:
<schema generated='yes'>
<table name='people' schema='public'>
...
</table>
<table name='accounts' schema='financial'>
...
</table>
...
</schema>
We have tables under 'schema', and each table has an attribute called
'schema' (unfortunate names, but not my choice).
What I need to do is to compile a unique list of nodes that are
comprised of the schema attributes.
In SQL, it would be:
select distinct (schema) from table;
I need it as a node list so that I can use xsl:for-each and iterate
through the list.
I'm currently working with the key() function, and I have the key
definition and the invocation.
The defintion is:
<xsl:key name='schemas_key' match='table' use='@schema' />
The usage is:
<xsl:variable name="schemas_var">
<xsl:for-each
select="table/@schema[generate-id(.)=generate-id(key('schemas_key',.)[1])]">
<xsl:sort select="." />
<xsl:copy-of select="." />
</xsl:for-each>
</xsl:variable>
This doesn't seem to work, and also, I get this message as the first
line of output:
xsltApplyOneTemplate: key was not compiled
Can anyone suggest an example for getting a unique or distinct list of
values for a particular attribute? What I have here is the best I've
been able to come up with so far by going through my books.
Thanks,
cf
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCWu66oaQ1/feGlJoRArt9AKCOGGn/5K43Dv7U4PRJ6Ekvz3Da9QCdGL6l
9l4lqhhkvO5Tm2Hg4t/pQME=
=bC1g
-----END PGP SIGNATURE-----
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]