At 2007-11-19 12:50 -0600, vwiswell(_at_)verizon(_dot_)net wrote:
I've looked at a lot of examples but I still can't seem to figure out
how to do this. I am using XSLT 2.0. I am transforming XML to XHTML.
There are some fundamental problems in your stylesheet, plus your
question is not quite clear.
The XML is something like this:
<corporation>
<company>
<employee>
<department>a</department>
</employee>
<employee>
<department>a</department>
</employee>
<employee>
<department>a</department>
</employee>
</company>
<company>
<employee>
<department>a</department>
</employee>
<employee>
<department>a</department>
</employee>
<employee>
<department>b</department>
</employee>
<employee>
<department>c</department>
</employee>
</company>
</corporation>
I need to group employees within a company (selected with a param) by
department. No problem. What I also need to do is include a table of
contents at the beginning of each department grouping linking to each
of the other department groups. If there is only one department in the
company, I do not display a table of contents.
I'm lost as to which groupings you need and which you do not. Could
you please show an example of what you want output from the data
above, rather than showing us the stylesheet. That shows us what
doesn't work, not what you want.
<xsl:for-each-group select="//company" group-by="department/text()">
<xsl:sort select="department/text()"/>
It is dangerous to use "/text()" in the above because of mixed
content. It is sufficient to say "department" because the text value
of an element is the concatenation of the descendant text nodes.
<br/>
<p><a id="<xsl:value-of
select='current-grouping-key()'/>"></a></p>
Your escaping of angle brackets in an attribute achieves
nothing. There is no such thing as element markup in an attribute
string. Use an attribute value template to do "value-of" in an attribute:
<a id="{current-grouping-key()}">
I think my problem is that I don't thoroughly understand how the XML
doc is processed so that I can get the group names at the beginning of
the the for-each-group.
What do you mean by a "group name"? If you mean the current grouping
key, then perhaps the above is all you need.
Remember also that you always get a group even if the count of
members of the group is one. If you don't want to do something if
there is only one member of the group, then you'll have to check the
count of the current group to determine that.
I hope this helps.
. . . . . . . . . . Ken
--
Comprehensive in-depth XSLT2/XSL-FO1.1 classes: Austin TX,Jan-2008
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds: publicly-available developer resources and training
G. Ken Holman mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers: http://www.CraneSoftwrights.com/legal
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--