Zhang Weiwu <> wrote in
<>:
> The system A produce XML output like this:
[snip "XML"]
No it doesn't. This is not well-formed. Are you sure you
want help from this group, or are you just aiming to annoy
people trying to help you?
> I am not sure if XSLT can handle such transformation?
Sure it can. It's one key and four simple templates:
<xsl:stylesheet version="1.0"
xmlns

sl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="y" match="yearly" use="@year"/>
<xsl:template match="/">
<result>
<xsl:apply-templates
select=
"
data/branch/yearly[count(.|key('y',@year)[1])=1]
" mode="group"/>
</result>
</xsl:template>
<xsl:template match="yearly" mode="group">
<xsl:copy>
<xsl:apply-templates select="@year"/>
<xsl:apply-templates select="key('y',@year)"/>
</xsl:copy>
</xsl:template>
<xsl:template match="yearly">
<branch>
<xsl:apply-templates select="../@name|*"/>
</branch>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
> Would be easy with SQL with distinct selection, but
> probably is the weakness of XSLT comparing to SQL?
XSLT is very different from SQL. XQuery is much closer to it
in terms of ideology and syntax but still doesn't bear
direct comparison. Hierarchical data and relational data
are simply too different for that.
--
It is rare to find learned men who are clean, do not stink,
and have a sense of humour. -- Liselotte in a letter to
Sophie, 30 Jul 1705