Hello Mathias
Thanks for trying, but that didn't seem to do it.
It allowed every element in the document to be output, so
maybe the fault lies with my description, so here's a
small chunk of the data:
<weird_doc>
<System name="ABC">...</System>
<System name="Whatever">...</System>
<System name="mail">
<Function name="Routing DB">...</Function>
<Function name="client">...</Function>
</System>
<System name="mail">
<Function name="pop3">...</Function>
<Function name="smtp">...</Function>
</System>
<System name="news">...</System>
<System name="account">...</System>
<System name="Authentication">...</System>
</weird_doc>
There will be many other System elements, some with matching values in their
'name' attributes, but to focus on this example, I'm trying get all the
children of <System name="mail"> under one instance of <System name="mail">,
which was easy, thanks to Ken Holman (and Steve Meunch, of course) and then
output all the other elements as they are.
This was the stylesheet:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version='1.0'>
<xsl:key name='systems' match='System[*]' use='@name'/>
<xsl:template match="/">
<xsl:for-each select="//System[generate-id(.)
=generate-id(key('systems', @name))]">
<System>
<xsl:copy-of select="@name"/>
<xsl:copy-of select="key('systems', @name)/*"/>
</System>
</xsl:for-each>
<xsl:if test="//*[@name and not (@name = following::*/@name)
and not (@name =preceding::*/@name)]">
<xsl:copy-of select='.'/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
It grouped all the Function children of System name="mail" under one
instance, but then it output the second instance of <System name="mail"> and
all the children thereof, too. I was hoping that the if test would detect
that another element had a 'name' attribute value of 'mail', and therefore
it wouldn't be output. Maybe the flaw is in my thinking (not unlikely).
Edmund
Try :
//*[@name and not (@name = following::*/@name) and not (@name =
preceding::*/@name)]
which should select all element nodes that have a 'name' attribute and
whose 'name' attribute's value is not present in the rest of the document
as an 'name' attribute...
There might be a simpler version (especially avoiding the double test on
preceding and following)...
Hope this helps.
Mathias Bonnard
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
Share information about yourself, create your own public profile at
http://profiles.msn.com.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list