Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 1st, 2007, 03:35 AM
Authorized User
 
Join Date: Jan 2006
Location: tel aviv, israel, Israel.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default re write a code

hello

in my code I have alot of template calls that look the same, but with different parameters.
is there a way to re-write it, so the code will look nicer and readable?
for example - calling the same templates with same parameters but different values.

<xsl:call-template name="common-time-display">
    <xsl:with-param name="v2" select="'total-time-display'"/>
    <xsl:with-param name="display" select="/etd/counters/counter/display/@sum-format"/>
    <xsl:with-param name="baseline_column_key" select="'TT_BL'"/>
    <xsl:with-param name="baseline_column_display" select="'!~stationTech!~-TT_BL'"/>
    <xsl:with-param name="tooltip_column_key" select="'TT'"/>
    <xsl:with-param name="tooltip_column_display" select="'!~stationTech!~-TT'"/>
    <xsl:with-param name="tooltip_baseline_template_key" select="concat(@dbcolumn, '_BL')"/>
    <xsl:with-param name="tooltip_baseline_template_display" select="concat('!~stationTech!~-', @dbcolumn, '_BL')"/>
    <xsl:with-param name="flag" select="'total'"/>
</xsl:call-template>
<xsl:call-template name="common-time-display">
    <xsl:with-param name="v2" select="'average-time-display'"/>
    <xsl:with-param name="display" select="/etd/counters/counter/display/@avg-format"/>
    <xsl:with-param name="baseline_column_key" select="'AVG_TT_BL'"/>
    <xsl:with-param name="baseline_column_display" select="'!~stationTech!~-AVG_TT_BL'"/>
    <xsl:with-param name="tooltip_column_key" select="'AVG_TT'"/>
    <xsl:with-param name="tooltip_column_display" select="'!~stationTech!~-AVG_TT'"/>
        <xsl:with-param name="tooltip_baseline_template_key" select="concat('AVG_', @dbcolumn, '_BL')"/>
    <xsl:with-param name="tooltip_baseline_template_display" select="concat('!~stationTech!~-', 'AVG_', @dbcolumn, '_BL')"/>
    <xsl:with-param name="flag" select="'avg'"/>
</xsl:call-template>

hope that I was clear enough.
Thanks
Kfir

 
Old August 1st, 2007, 03:53 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You could try passing a single parameter which is an XML fragment containing all the information needed. However, you're limited because in XSLT 1.0 you can't address inside a result-tree-fragment without the xx:node-set() extension.

This does seem a surprisingly large number of parameters. Also, most of them seem to vary between the two calls only by the prefixing of "AVG_" to the value. This suggests that there is some refactoring possible.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 1st, 2007, 07:15 AM
Authorized User
 
Join Date: Jan 2006
Location: tel aviv, israel, Israel.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

what kind of refactoring did you had in mind?
since all the parameters are different, even though they have AVG_.
do you maybe have an example?

 
Old August 1st, 2007, 07:40 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I wouldn't attempt a refactoring without knowing a lot more about the application as a whole. But when I see two bits of code as similar as the two you showed, and especially if there were several more that followed the same pattern, then I would be looking for another layer of template that takes fewer parameters.

However, XSLT 1.0 is always going to be verbose, there's no way around it. Move to 2.0 if you can.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference




Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i write code to go back or undo sanderson Beginning VB 6 1 July 9th, 2008 05:10 PM
Need help, what code should I write here? vincentleo ASP.NET 2.0 Basics 2 March 10th, 2008 10:09 AM
how write vb code in c# ravpaw General .NET 2 July 1st, 2007 02:13 PM
How to write code to draw bouncing circles Bimbo VB How-To 1 November 11th, 2005 02:17 PM
Can I write ASP code in Dreamweaver? Ben Horne Dreamweaver (all versions) 13 December 4th, 2003 04:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.