| |
5. 2. 2. output method="xml" indent="yes" encoding="ISO-8859-1" |
|
File: Data.xml
<?xml version="1.0" encoding="UTF-8"?>
<europe>
<scandinavia>
<state>Finland</state>
<state>Sweden</state>
<state>Iceland</state>
<state>Norway</state>
<state>Denmark</state>
</scandinavia>
</europe>
File: Transform.xslt
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.java2java.com"
xmlns:sc="http://www.java2java.com/scand"
xmlns:t="http://www.java2java.com/temp">
<xsl:output method="xml" indent="yes" encoding="ISO-8859-1" />
<xsl:namespace-alias stylesheet-prefix="t" result-prefix="xsl" />
<xsl:template match="europe">
<t:stylesheet version="1.0">
<t:output method="xml" indent="yes" encoding="ISO-8859-1" />
<t:namespace-alias stylesheet-prefix="sc" result-prefix="#default" />
<xsl:text> </xsl:text>
<t:template match="{name()}">
<t:apply-templates select="scandinavia" />
</t:template>
<xsl:text> </xsl:text>
<xsl:apply-templates select="scandinavia" />
<xsl:apply-templates select="scandinavia/state[1]" />
<xsl:text> </xsl:text>
</t:stylesheet>
</xsl:template>
<xsl:template match="scandinavia">
<xsl:text> </xsl:text>
<t:template match="{name()}">
<sc:scandinavia>
<t:apply-templates select="state">
<t:sort />
</t:apply-templates>
</sc:scandinavia>
</t:template>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="state">
<xsl:text> </xsl:text>
<t:template match="{name()}">
<sc:country>
<t:value-of select="." />
</sc:country>
</t:template>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
Output:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:sc="http://www.java2java.com/scand"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.java2java.com"
version="1.0">
<xsl:output method="xml" indent="yes" encoding="ISO-8859-1"/>
<xsl:namespace-alias stylesheet-prefix="sc" result-prefix="#default"/>
<xsl:template match="europe">
<xsl:apply-templates select="scandinavia"/>
</xsl:template>
<xsl:template match="scandinavia">
<sc:scandinavia>
<xsl:apply-templates select="state">
<xsl:sort/>
</xsl:apply-templates>
</sc:scandinavia>
</xsl:template>
<xsl:template match="state">
<sc:country>
<xsl:value-of select="."/>
</sc:country>
</xsl:template>
</xsl:stylesheet>
|
|
|