XSL John Smith

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

<source>

<title>XSL</title>
<author>John Smith</author>
</source>

<xsl:stylesheet version = '1.0'

xmlns:xsl='http://www.w3.org/1999/XSL/T
ransform'>

<xsl:template match="/">
<h1>
<xsl:value-of select="//title"/>
</h1>
<h2>
<xsl:value-of select="//author"/>
</h2>
</xsl:template>

</xsl:stylesheet>
<source>
<title>XSL</title>
<author>John Smith</author>
</source>

<xsl:stylesheet version = '1.0'

xmlns:xsl='http://www.w3.org/1999/XSL/T
ransform'>

<xsl:template match="/">
<h2>
<xsl:value-of select="//author"/>
</h2>
<h1>
<xsl:value-of select="//title"/>
</h1>
</xsl:template>

</xsl:stylesheet>
<xsl:stylesheet version = '1.0'
<source>
<bold>Hello, world.</bold> xmlns:xsl='http://www.w3.org/1999/XSL/T
<red>I am </red> ransform’>
<italic>fine.</italic> <xsl:template match="bold">
</source> <p>
<b>
<xsl:value-of select="."/>
</b>
</p>
</xsl:template>
<xsl:template match="red">
<p style="color:red">
<xsl:value-of select="."/>
</p>
</xsl:template>
<xsl:template match="italic">
<p>
<i>
<xsl:value-of select="."/>
</i>
</p>
</xsl:template>
</xsl:stylesheet>
<source> <xsl:stylesheet version = '1.0'

<employee> xmlns:xsl='http://www.w3.org/1999/XSL/T
ransform'>
<firstName>Joe</firstName>
<surname>Smith</surname> <xsl:template match="employee">
</employee> <b>
<xsl:value-of select="."/>
</source> </b>
</xsl:template>

<xsl:template match="surname">
<i>
<xsl:value-of select="."/>
</i>
</xsl:template>

</xsl:stylesheet>
<source> <xsl:stylesheet version = '1.0'

<employee> xmlns:xsl='http://www.w3.org/1999/XSL/Trans
form'>
<firstName>Joe</firstName>
<surname>Smith</surname> <xsl:template match="employee">
</employee> <b>
<xsl:apply-templates select="firstName"/>
</source> </b>
<b>
<xsl:apply-templates select="surname"/>
</b>
</xsl:template>

<xsl:template match="surname">
<i>
<xsl:value-of select="."/>
</i>
</xsl:template>

</xsl:stylesheet>
<xsl:stylesheet version = '1.0'
<source>
xmlns:xsl='http://www.w3.org/1999/XSL/Trans
<bold>Hello, world.</bold> form'>
<red>I am </red>
<italic>fine.</italic> <xsl:template match="bold">
<p>
<b>
</source> <xsl:value-of select="."/>
</b>
</p>
</xsl:template>
<xsl:template match="red">
<p style="color:red">
<xsl:value-of select="."/>
</p>
</xsl:template>
<xsl:template match="italic">
<p>
<i>
<xsl:value-of select="."/>
</i>
</p>
</xsl:template>
<xsl:stylesheet version = '1.0'
<source>
<AAA id="a1" pos="start"> xmlns:xsl='http://www.w3.org/1999/XSL/Trans
<BBB id="b1"/> form'>
<BBB id="b2"/>
</AAA> <xsl:template match="BBB">
<div style="color:purple">
<AAA id="a2">
<xsl:value-of select="name()"/>
<BBB id="b3"/> <xsl:text> id=</xsl:text>
<BBB id="b4"/> <xsl:value-of select="@id"/>
<CCC id="c1"> </div>
<DDD id="d1"/> </xsl:template>
</CCC>
<BBB id="b5"> <xsl:template
<CCC id="c2"/> match="/source/AAA/CCC/DDD">
</BBB> <p style="color:red">
<xsl:value-of select="name()"/>
</AAA>
<xsl:text> id=</xsl:text>
</source> <xsl:value-of select="@id"/>
</p>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version = '1.0'
<source>
<AAA id="a1" pos="start"> xmlns:xsl='http://www.w3.org/1999/XSL/Trans
<BBB id="b1"/> form'>
<BBB id="b2"/>
</AAA> <xsl:template match="/">
<xsl:apply-templates/>
<AAA id="a2">
</xsl:template>
<BBB id="b3"/>
<BBB id="b4"/> <xsl:template match="/source">
<CCC id="c1"> <xsl:apply-templates/>
<DDD id="d1"/> </xsl:template>
</CCC>
<BBB id="b5"> <xsl:template match="AAA">
<CCC id="c2"/> <div style="color:purple">
</BBB> <xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
</AAA>
<xsl:value-of select="@id"/>
</source> </div>
</xsl:template>

</xsl:stylesheet>
<xsl:stylesheet version = '1.0'
<source> xmlns:xsl='http://www.w3.org/1999/XSL/Transform’>
<xsl:template match="/">
<AAA id="a1" pos="start"> <xsl:apply-templates/>
<BBB id="b1"/> </xsl:template>
<xsl:template match="/xslTutorial">
<BBB id="b2"/> <xsl:apply-templates/> </xsl:template>
</AAA> <xsl:template match="AAA">
<div style="color:purple">
<AAA id="a2"> <xsl:value-of select="name()"/>
<BBB id="b3"/> <xsl:text> id=</xsl:text>
<BBB id="b4"/> <xsl:value-of select="@id"/>
</div> <xsl:apply-templates/> </xsl:template>
<CCC id="c1"> <xsl:template match="BBB">
<DDD id="d1"/> <div style="color:blue">
<xsl:value-of select="name()"/>
</CCC> <xsl:text> id=</xsl:text>
<BBB id="b5"> <xsl:value-of select="@id"/>
</div> <xsl:apply-templates/> </xsl:template>
<CCC id="c2"/> <xsl:template match="CCC">
</BBB> <div style="color:maroon">
</AAA> <xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
</source> <xsl:value-of select="@id"/>
</div> <xsl:apply-templates/> </xsl:template>
<xsl:template match="DDD">
<div style="color:green">
<xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
<xsl:value-of select="@id"/>
</div> </xsl:template></xsl:stylesheet>
<xsl:stylesheet version = '1.0'
<source>
xmlns:xsl='http://www.w3.org/1999/XSL/Tran
<employee> form’>
<firstName>Joe</firstName> <xsl:template match="firstName|surname">
<surname>Smith</surname> <div>
<xsl:text>[template: </xsl:text>
</employee>
<xsl:value-of select="name()"/>
<xsl:text> outputs </xsl:text>
</source> <xsl:apply-templates/>
<xsl:text> ]</xsl:text>
<xsl:stylesheet version = '1.0' </div>
</xsl:template>
xmlns:xsl='http://www.w3.org/1999/XSL/Trans </xsl:stylesheet>
form’>
<xsl:template match= "*">
<div>
<xsl:text>[template: </xsl:text>
<xsl:value-of select="name()"/>
<xsl:text> outputs </xsl:text>
<xsl:apply-templates/>
<xsl:text> ]</xsl:text>
</div>
</xsl:template>
<xsl:stylesheet version = '1.0'
<source> xmlns:xsl='http://www.w3.org/1999/XSL/Transform’>
<xsl:template match="/">
<AAA id="a1" pos="start"> <xsl:apply-templates select="//BBB"/>
<BBB id="b1"/> <xsl:apply-templates select="//CCC"/>
<xsl:apply-templates select="//DDD"/>
<BBB id="b2"/> <xsl:apply-templates select="//AAA"/></xsl:template>
</AAA> <xsl:template match="AAA">
<div style="color:navy">
<AAA id="a2"> <xsl:value-of select="name()"/>
<BBB id="b3"/> <xsl:text> id=</xsl:text>
<BBB id="b4"/> <xsl:value-of select="@id"/>
</div> </xsl:template>
<CCC id="c1"> <xsl:template match="BBB">
<DDD id="d1"/> <div style="color:purple">
<xsl:value-of select="name()"/>
</CCC> <xsl:text> id=</xsl:text>
<BBB id="b5"> <xsl:value-of select="@id"/>
</div> </xsl:template>
<CCC id="c2"/> <xsl:template match="CCC">
</BBB> <div style="color:red">
</AAA> <xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
</source> <xsl:value-of select="@id"/>
</div> </xsl:template>
<xsl:template match="DDD">
<div style="color:blue">
<xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
<xsl:value-of select="@id"/> </div> </xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform’>
<source> <xsl:template match="/">
<table border="1" cellpadding="6">
<AAA id="a1" pos="start"> <tr>
<BBB id="b1"/> <th colspan="2">Axis: child</th>
<BBB id="b2"/> </tr>
<tr>
</AAA> <th>Element</th>
<AAA id="a2"> <th>Node-set</th>
</tr>
<BBB id="b3"/> <xsl:for-each select="/source//*">
<BBB id="b4"/> <xsl:call-template name="print"/>
</xsl:for-each>
<CCC id="c1"> </table>
<DDD id="d1"/> </xsl:template>
</CCC> <xsl:template name="print">
<tr>
<BBB id="b5"> <td>
<CCC id="c2"/> <xsl:value-of select="name()"/>
<xsl:text> id = </xsl:text>
</BBB> <xsl:value-of select="./@id"/>
</AAA> </td>
<td>
</source> <xsl:for-each select="child::*">
<xsl:value-of select="./@id"/>
<xsl:text/>
</xsl:for-each>
</td>
</tr>
</xsl:template></xsl:stylesheet>

You might also like