Wednesday, April 22, 2009

Recursive XSLT




product.xsl

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:param name="numCols" select="3"/>
<table cellpadding="0" cellspacing="5" border="0">
<xsl:call-template name="renderColumns">
<xsl:with-param name="listrows" select="//product"/>
<xsl:with-param name="startindex" select="1"/>
<xsl:with-param name="numofCols" select="$numCols"/>
</xsl:call-template>
</table>
</xsl:template>

<xsl:template name="renderColumns">
<xsl:param name="listrows" />
<xsl:param name="startindex"/>
<xsl:param name="numofCols"/>
<xsl:if test="count($listrows) > 0">
<tr>
<xsl:apply-templates
select="$listrows[position() >=
$startindex and position() <
($startindex+$numofCols)]"
mode="rows">
</xsl:apply-templates>
</tr>
<xsl:call-template name="renderColumns">
<xsl:with-param name="listrows"
select="$listrows[position() >= $startindex+$numofCols]"/>
<xsl:with-param name="startindex" select="$startindex"/>
<xsl:with-param name="numofCols" select="$numofCols"/>
</xsl:call-template>
</xsl:if>
</xsl:template>

<xsl:template match="node()" mode="rows">
<td nowrap="true">
<table style="width:100%;border-right: thin solid;
border-top: thin solid; border-left:
thin solid; border-bottom: thin solid;"
>
<xsl:apply-templates select="@*"/>
</table>
</td>
</xsl:template>

<xsl:template match="@*">
<tr>
<td style="font-size: larger; text-transform:
uppercase; background-color: gainsboro"
>
<xsl:value-of select="name()"/>
</td>
<td>
<xsl:value-of select="."/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>


product.xml

<data> 
<product name="Heine HKL with trolleystand"
price="230.45" weight="34.4kg" />
<product name="Universal clamp and Projector"
price="670.45" weight="10.64kg" />
<product name="Examination Lamp, Universal Mount"
price="25.45" weight="1.08kg" />
<product name="Provita Examination Lamp, Mobile Base"
price="215.45" weight="1.4kg" />
<product name="35Watt Flexible Arm Light to fit Rail system"
price="130.45" weight="11.67kg" />

</data>



output:

Thursday, April 2, 2009

JSON

JSON (JavaScript Object Notation) is a lightweight data-interchange format

Tuesday, March 31, 2009