J
JimLad
Hi,
We're using XSLT to transform XML data into an HTML table. With 200
rows of data, this is taking 10s which I consider to be excessive to
say the least. I'm afraid I use XSLT so rarely that I have to relearn
everything each time I do. Any help in sorting this out would be
appreciated. I'm sure the same advice would apply to all our
transforms so it would be very helpful.
XML sample:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<member_salaries member_salary_id="791628" member_id="150230"
salary_type_id="25" start_date="2005-06-01" salary="103.73" />
<member_salaries member_salary_id="791629" member_id="150230"
salary_type_id="25" start_date="2006-05-01" end_date="2006-05-31"
salary="32.12" />
</root>
XSLT (I have removed some of the HTML markup):
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:custom="/">
<msxsl:script language="vbscript" implements-prefix="custom">
<![CDATA[
Function dateFormat(x)
if x="" then
dateFormat = ""
exit function
end if
dateFormat = numberFormat(day(x)) & "/" & numberFormat(month(x)) &
"/" & year(x)
End Function
Function numberFormat(x)
if x="" then exit function
if x < 10 then numberFormat = "0" & x else numberFormat = x
End Function
]]>
</msxsl:script>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="//member_salaries">
<FORM ID="Form1">
<table >
<thead>
</thead>
<tbody >
<xsl:apply-templates select="//member_salaries">
<xsl:sort select="@salary_type_order"
order="ascending" data-type="text" />
<xsl:sort select="@start_date" order="descending" data-
type="text" />
</xsl:apply-templates>
<tr >
</td>
</tr>
</tbody>
</table>
</FORM>
</xsl:when>
<xsltherwise>
There are no entries which match your selection.
</xsltherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="//member_salaries">
<tr >
<td>
<input id="member_salary_id" name="member_salary_id"
type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="@member_salary_id"/>
</xsl:attribute>
</input>
</td>
<td>
<input id="member_id" name="member_id" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="@member_id"/>
</xsl:attribute>
</input>
</td>
<td>
<input id="status_change_date" name="status_change_date"
type="hidden">
<xsl:attribute name="value"></xsl:attribute>
</input>
</td>
<xsl:variable name="salaryTypeId" select="@salary_type_id"/>
<td>
<SELECT id="salary_type_id" NAME="salary_type_id">
<xsl:for-each select="//salary_types">
<xsl:sort select="@salary_type" order="ascending" data-
type="text" />
<option>
<xsl:if test="@salary_type_id=$salaryTypeId">
<xsl:attribute name="selected">selected</
xsl:attribute>
</xsl:if>
<xsl:attribute name="value">
<xsl:value-of select="@salary_type_id"/>
</xsl:attribute>
<xsl:value-of select="@salary_type"/>
</option>
</xsl:for-each>
</SELECT>
</td>
<td>
<input size="7" id="start_date" name="start_date" >
<xsl:attribute name="value">
<xsl:apply-templates select="@start_date"/>
</xsl:attribute>
</input>
</td>
<td>
<input size="7" id="end_date" name="end_date" >
<xsl:attribute name="value">
<xsl:apply-templates select="@end_date"/>
</xsl:attribute>
</input>
</td>
<td>
<input size="10" id="salary" name="salary" >
<xsl:attribute name="value">
<xsl:value-of select="@salary"/>
</xsl:attribute>
</input>
</td>
</tr>
</xsl:template>
<xsl:template match="@start_date | @end_date">
<xsl:value-of select="custom:dateformat(string(.))"/>
</xsl:template>
<xsl:template match="//row/@Start_date">
<xsl:value-of select="custom:dateformat(string(.))"/>
</xsl:template>
</xsl:stylesheet>
Cheers,
James
We're using XSLT to transform XML data into an HTML table. With 200
rows of data, this is taking 10s which I consider to be excessive to
say the least. I'm afraid I use XSLT so rarely that I have to relearn
everything each time I do. Any help in sorting this out would be
appreciated. I'm sure the same advice would apply to all our
transforms so it would be very helpful.
XML sample:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<member_salaries member_salary_id="791628" member_id="150230"
salary_type_id="25" start_date="2005-06-01" salary="103.73" />
<member_salaries member_salary_id="791629" member_id="150230"
salary_type_id="25" start_date="2006-05-01" end_date="2006-05-31"
salary="32.12" />
</root>
XSLT (I have removed some of the HTML markup):
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:custom="/">
<msxsl:script language="vbscript" implements-prefix="custom">
<![CDATA[
Function dateFormat(x)
if x="" then
dateFormat = ""
exit function
end if
dateFormat = numberFormat(day(x)) & "/" & numberFormat(month(x)) &
"/" & year(x)
End Function
Function numberFormat(x)
if x="" then exit function
if x < 10 then numberFormat = "0" & x else numberFormat = x
End Function
]]>
</msxsl:script>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="//member_salaries">
<FORM ID="Form1">
<table >
<thead>
</thead>
<tbody >
<xsl:apply-templates select="//member_salaries">
<xsl:sort select="@salary_type_order"
order="ascending" data-type="text" />
<xsl:sort select="@start_date" order="descending" data-
type="text" />
</xsl:apply-templates>
<tr >
</td>
</tr>
</tbody>
</table>
</FORM>
</xsl:when>
<xsltherwise>
There are no entries which match your selection.
</xsltherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="//member_salaries">
<tr >
<td>
<input id="member_salary_id" name="member_salary_id"
type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="@member_salary_id"/>
</xsl:attribute>
</input>
</td>
<td>
<input id="member_id" name="member_id" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="@member_id"/>
</xsl:attribute>
</input>
</td>
<td>
<input id="status_change_date" name="status_change_date"
type="hidden">
<xsl:attribute name="value"></xsl:attribute>
</input>
</td>
<xsl:variable name="salaryTypeId" select="@salary_type_id"/>
<td>
<SELECT id="salary_type_id" NAME="salary_type_id">
<xsl:for-each select="//salary_types">
<xsl:sort select="@salary_type" order="ascending" data-
type="text" />
<option>
<xsl:if test="@salary_type_id=$salaryTypeId">
<xsl:attribute name="selected">selected</
xsl:attribute>
</xsl:if>
<xsl:attribute name="value">
<xsl:value-of select="@salary_type_id"/>
</xsl:attribute>
<xsl:value-of select="@salary_type"/>
</option>
</xsl:for-each>
</SELECT>
</td>
<td>
<input size="7" id="start_date" name="start_date" >
<xsl:attribute name="value">
<xsl:apply-templates select="@start_date"/>
</xsl:attribute>
</input>
</td>
<td>
<input size="7" id="end_date" name="end_date" >
<xsl:attribute name="value">
<xsl:apply-templates select="@end_date"/>
</xsl:attribute>
</input>
</td>
<td>
<input size="10" id="salary" name="salary" >
<xsl:attribute name="value">
<xsl:value-of select="@salary"/>
</xsl:attribute>
</input>
</td>
</tr>
</xsl:template>
<xsl:template match="@start_date | @end_date">
<xsl:value-of select="custom:dateformat(string(.))"/>
</xsl:template>
<xsl:template match="//row/@Start_date">
<xsl:value-of select="custom:dateformat(string(.))"/>
</xsl:template>
</xsl:stylesheet>
Cheers,
James