I'm new in xml and I'am trying to understand a example of xslt
the xml
<?xml version="1.0" encoding="utf-8"?>
<ts>
<t id="t1">T1</t>
<t id="t2" ref="t1">T2</t>
<t id="t3" ref="t2">T3</t>
</ts>
1) the first xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="key" match="t" use="@id"/>
<xsl:template match="/|*|text()">
<xsl:copy>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/t[@ref]">
<xsl:copy-of select="key('key',@ref)"/>
</xsl:template>
</xsl:stylesheet>
2) the second xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="key" match="t" use="@id"/>
<xsl:template match="/|*|text()">
<xsl:copy>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="t[@ref]">
<xsl:apply-templates select="key('key',@ref)"/>
</xsl:template>
</xsl:stylesheet>
and the results are: 1)
<?xml version="1.0"?>
<ts>
<t>T1</t>
<t id="t1">T1</t>
<t id="t2" ref="t1">T2</t>
</ts>
2)
<?xml version="1.0"?>
<ts>
<t>T1</t>
<t>T1</t>
<t>T1</t>
</ts>
can anybody tells me how it works especially the second xsl how it gives the result with three T1. Thanks a lot for your help :)