XSL : (xslt , xpath , xsl-fo )

Transform XML element to Xhtml or html

 

1. Root element : <xsl:stylesheet> </xsl:stylesheet>
eg <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

2. Build template
<xsl:template match="/"> </xsl:template> //match is used to assocated XML element


3. Looping XML element : <xsl:for-each select=""/> //entire XML file

4. Sort element: <xsl:sort>

5. condition test: <xsl:if> </xsl:if>

6. Choose -> When ->otherwise :

<xsl:choose>
<xsl:when test="price &gt; 10">

</xsl:when>
<xsl:otherwise>

</xsl:othersie>
</xsl:choose>


7: Apply template to all element and its child node : <xsl:template match="/">
match= " " give you choice to choose element

8.Select element :< xsl:value-of select="artist"/>

Example

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">.

<xsl:template match="/">

<html>

<head>
<title> My CD Collection </title>
</head>


<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>

<!-- <xsl:apply-template/> -->

<xsl:for-each select="catalog/cd">
<tr>

<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>

</table>
</body>

</html>
</xsl:template>


</xsl:stylesheet>

 

Xml to Xhtml JAVA SCRIPT

Client Side

Transform.htm

<html>
<head>

<script type="text/javascript">

// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("titles.xml")

// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("titletransformall.xsl")

// Transform
document.write(xml.transformNode(xsl))

</script>
</head>

</body>
</body>
</html>

Server Side Transform

(send xhtml back to browser, for all browser)

<Script runat="server" language="c#" >
void titletransform(Object s, EventArgs e)
{
titles.DocumentSource="xml/titles.xml" ;

if(chktitles.Checked)
{
titles.TransformSource="xml/titletransformall.xsl";
}
else
titles.TransformSource="xml/titletransform.xsl";

}

</script>

<form runat="server">

<asp:CheckBox id="chktitles" AutoPostBack="true" OnCheckedChanged="titletransform" Text="Show All" runat="server" />


<asp:xml id="titles" runat="server" /> //xml web control

</form>

 

 

 

 

@Copy right of Soon Lim 2006. All Right Reserved