File: Data.xml
<?xml version = "1.0"?>
<sports>
<game title = "cricket">
<id>243</id>
<para>
para 1
</para>
</game>
<game title = "baseball">
<id>431</id>
<para>
para 2
</para>
</game>
<game title = "soccer">
<id>123</id>
<para>
para 3
</para>
</game>
</sports>
File: Transform.xslt
<?xml version = "1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="sports">
<sports>
<xsl:apply-templates />
</sports>
</xsl:template>
<xsl:template match="game">
<xsl:element name="{@title}">
<xsl:attribute name="id">
<xsl:value-of select="id" />
</xsl:attribute>
<comment>
<xsl:value-of select="para" />
</comment>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Output:
<?xml version="1.0" encoding="UTF-8"?><sports>
<cricket id="243"><comment>
para 1
</comment></cricket>
<baseball id="431"><comment>
para 2
</comment></baseball>
<soccer id="123"><comment>
para 3
</comment></soccer>
</sports>
|