Project

Profile

Help

avoiding duplicate apply-templates calls

Added by Anonymous about 19 years ago

Legacy ID: #3051940 Legacy Poster: Jeff (jeff_i)

Hi all, I am trying to avoid calling apply-templates for the same template more than once to improve performance. When I put the apply-templates (the template w/ mode="groupingsummary") in a variable ($rowsum) , my html tags get dropped when I use <xsl:value-of select="$rowsum"/>. When I make the template call twice, the html is valid. xml and xslt below. Thanks for any help, Jeff <!--xml --> <?xml version="1.0" encoding="ISO-8859-1"?> <dataapp> <content> <resultset> <rs-meta> <id>table836411</id> <title>Report Title</title> <rs-columns> <col type="string">Category</col> <col name="ItemNo" type="string">Item No</col> <col name="Item" type="string">Item</col> <col eq="SUM(Mar_03)" name="Mar_03" type="currency">Mar03</col> <col eq="SUM(Mar_04)" name="Mar_04" type="currency">Mar04</col> </rs-columns> </rs-meta> <rs-data> <group id="group31706231_0" label="Category 1"> <groupsummary> <col name="Category">Category</col> <col name="ItemNo" type="string"/> <col name="Item" type="string"/> <col eq="SUM(Mar_03)" name="Mar_03" type="currency"/> <col eq="SUM(Mar_04)" name="Mar_04" type="currency"/> </groupsummary> <groupdetail> <row index="0"> <col name="Category">Category 1</col> <col name="ItemNo">102000</col> <col name="Item">Item 1aa</col> <col name="Mar_03">15297.6</col> <col name="Mar_04">3936</col> </row> <row index="1"> <col name="Category">Category 1</col> <col name="ItemNo">101000</col> <col name="Item">Item 1ab </col> <col name="Mar_03">9387.36</col> <col name="Mar_04">5872.8</col> </row> <row index="2"> <col name="Category">Category 1</col> <col name="ItemNo">105000</col> <col name="Item">Item 1ac</col> <col name="Mar_03">4686.72</col> <col name="Mar_04">5898.8</col> </row> <row index="3"> <col name="Category">Category 1</col> <col name="ItemNo">103000</col> <col name="Item">Item 1ad</col> <col name="Mar_03">8795.28</col> <col name="Mar_04">5898.8</col> </row> </groupdetail> </group> <group id="group8694274_1" label="Category 2"> <groupsummary> <col name="Category">Category</col> <col name="ItemNo" type="string"/> <col name="Item" type="string"/> <col eq="SUM(Mar_03)" name="Mar_03" type="currency"/> <col eq="SUM(Mar_04)" name="Mar_04" type="currency"/> </groupsummary> <groupdetail> <row index="4"> <col name="Category">Category 2</col> <col name="ItemNo">093000</col> <col name="Item">Item 2aa</col> <col name="Mar_03">11046.24</col> <col name="Mar_04">3699.36</col> </row> <row index="5"> <col name="Category">Category 2</col> <col name="ItemNo">095000</col> <col name="Item">Item 2ab</col> <col name="Mar_03">8419.68</col> <col name="Mar_04">0</col> </row> </groupdetail> </group> </rs-data> </resultset> </content> </dataapp> <!--xslt --> <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" omit-xml-declaration="no" encoding="iso-8859-1" indent="yes" /> <xsl:strip-space elements="*"/> <xsl:template match="/"> <xsl:apply-templates select="dataapp"/> </xsl:template> <xsl:template match="dataapp"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>Boring Title</title> </head> <body> <form name="dataapp" method="get"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td> <xsl:apply-templates select="content/resultset"/> </td> </tr> </table> </form> </body> </html> </xsl:template> <xsl:template match="resultset"> <div> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td>Awesome Title</td> </tr> <xsl:apply-templates select="rs-meta/rs-columns" mode="normaltable"/> <xsl:apply-templates select="rs-data" mode="normaltable"/> </table> </div> </xsl:template> <xsl:template match="rs-data//row" mode="normaltable"> <tr> <xsl:apply-templates mode="normaltable"/> </tr> </xsl:template> <xsl:template match="rs-columns/col" mode="normaltable"> <td> <xsl:value-of select="."/> </td> </xsl:template> <xsl:template match="rs-data//group" mode="normaltable"> <tr> <td> <xsl:value-of select="@label"/> </td> </tr> <xsl:variable name="rowsum"> <!-- This apply-templates call is listed twice below (in comments) and I do not want to call twice! (Performance reasons) I am stuffing it in a variable for now --> <xsl:apply-templates select="groupsummary/col" mode="groupingsummary"> <xsl:with-param name="forcerowtype" select="'rs-gsum1'"/> </xsl:apply-templates> </xsl:variable> <!-- Print summary row --> <tr> <!-- Commenting out duplication <xsl:apply-templates select="groupsummary/col" mode="groupingsummary"> <xsl:with-param name="forcerowtype" select="'rs-gsum1'"/> </xsl:apply-templates> --> <xsl:value-of select="$rowsum"/> </tr> <xsl:apply-templates select="groupdetail" mode="normaltable"/> <!-- Print summary row --> <tr> <!-- Commenting out duplication <xsl:apply-templates select="groupsummary/col" mode="groupingsummary"> <xsl:with-param name="forcerowtype" select="'rs-gsum1'"/> </xsl:apply-templates> --> <xsl:value-of select="$rowsum"/> </tr> </xsl:template> <xsl:template match="col" mode="normaltable"> <xsl:variable name="currentname" select="@name"/> <xsl:variable name="coltype" select="ancestor::resultset/rs-meta/rs-columns/col[@name = $currentname]/@type"/> <td> <xsl:value-of select="."/> </td> </xsl:template> <xsl:template match="col" mode="groupingsummary"> <xsl:param name="forcerowtype"/> <xsl:choose> <xsl:when test="@eq/."> <xsl:apply-templates select="." mode="equation"/> <td> <xsl:value-of select="@eq/."/> </td> </xsl:when> <xsl:when test="@type = 'currency' or @type = 'number' or @type = 'percentage'"> <td> </td> </xsl:when> <xsl:otherwise> <td> <xsl:value-of select="."/> </td> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>


Replies (1)

RE: avoiding duplicate apply-templates calls - Added by Anonymous about 19 years ago

Legacy ID: #3052415 Legacy Poster: Michael Kay (mhkay)

<xsl:value-of> creates a text node, by taking the string-value of the expression in the select attribute. If this expression is a tree, its string-value is the concatenation of all its text nodes. If you want to copy the complete structure of a tree-valued variable, use xsl:copy-of. Michael Kay

    (1-1/1)

    Please register to reply