Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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

Reply With Quote
  #2 (permalink)  
Old August 1st, 2007, 03:53 AM
mhkay's Avatar
Wrox Author
Points: 18,410, Level: 59
Points: 18,410, Level: 59 Points: 18,410, Level: 59 Points: 18,410, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,949
Thanks: 0
Thanked 289 Times in 284 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
Reply With Quote
  #3 (permalink)  
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?

Reply With Quote
  #4 (permalink)  
Old August 1st, 2007, 07:40 AM
mhkay's Avatar
Wrox Author
Points: 18,410, Level: 59
Points: 18,410, Level: 59 Points: 18,410, Level: 59 Points: 18,410, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,949
Thanks: 0
Thanked 289 Times in 284 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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 01:17 PM
Can I write ASP code in Dreamweaver? Ben Horne Dreamweaver (all versions) 13 December 4th, 2003 03:00 PM



All times are GMT -4. The time now is 05:24 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.