Mega Code Archive

 
Categories / XML Tutorial / XSLT StyleSheet
 

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.rntsoft.com"   xmlns:sc="http://www.rntsoft.com/scand"   xmlns:t="http://www.rntsoft.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>&#10;&#10;</xsl:text>       <t:template match="{name()}">         <t:apply-templates select="scandinavia" />       </t:template>       <xsl:text>&#10;</xsl:text>       <xsl:apply-templates select="scandinavia" />       <xsl:apply-templates select="scandinavia/state[1]" />       <xsl:text>&#10;</xsl:text>     </t:stylesheet>   </xsl:template>   <xsl:template match="scandinavia">     <xsl:text>&#10;</xsl:text>     <t:template match="{name()}">       <sc:scandinavia>         <t:apply-templates select="state">           <t:sort />         </t:apply-templates>       </sc:scandinavia>     </t:template>     <xsl:text>&#10;</xsl:text>   </xsl:template>   <xsl:template match="state">     <xsl:text>&#10;</xsl:text>     <t:template match="{name()}">       <sc:country>         <t:value-of select="." />       </sc:country>     </t:template>     <xsl:text>&#10;</xsl:text>   </xsl:template> </xsl:stylesheet> Output: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:sc="http://www.rntsoft.com/scand"                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"                 xmlns="http://www.rntsoft.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>