File: Data.xml
<?xml version="1.0" encoding="UTF-8"?>
<eu>
<member>
<state>Austria</state>
<state founding="yes">Belgium</state>
</member>
<candidate>
<state>Poland</state>
<state>Romania</state>
<state>Slovakia</state>
<state>Slovenia</state>
<state>Turkey</state>
</candidate>
</eu>
File: Transform.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="eu">
<xsl:copy>
<xsl:comment>
<xsl:text>Member states: </xsl:text>
<xsl:value-of select="count(member/state)" />
</xsl:comment>
<xsl:copy-of select="member" />
<xsl:comment>
<xsl:text>Candidate states: </xsl:text>
<xsl:value-of select="count(candidate/state)" />
</xsl:comment>
<xsl:copy-of select="candidate" />
<xsl:comment>
<xsl:text>Other states: </xsl:text>
<xsl:value-of
select="count(document('other.xml')/eu/other/state)" />
</xsl:comment>
<xsl:copy-of select="document('other.xml')/eu/other" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Output:
<?xml version="1.0" encoding="UTF-8"?>
<eu><!--Member states: 2--><member>
<state>Austria</state>
<state founding="yes">Belgium</state>
</member>
<!--Candidate states: 5--><candidate>
<state>Poland</state>
<state>Romania</state>
<state>Slovakia</state>
<state>Slovenia</state>
<state>Turkey</state>
</candidate>
<!--Other states: 0--></eu>
|