Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 July 18th, 2007, 02:53 AM
Authorized User
 
Join Date: Jan 2006
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default array template

hello

I would like to know if I can make this more efficency, rather then call a template for each time.
my xsl:

<xsl:template name="CA-graph">
<xsl:param name="CA_entity"/>
<xsl:param name="i"/>
   <xsl:if test="count(/etd/entities/entity/data[@class=$CA_entity]) = 0">
    <xsl:attribute name = "{concat('v',$i)}">
        <xsl:value-of select="$CA_entity"/>
    </xsl:attribute>
   </xsl:if>
</xsl:template>


<xsl:call-template name="CA-graph">
  <xsl:with-param name="CA_entity" select="'activity'"/>
  <xsl:with-param name="i" select="'2'"/>
</xsl:call-template>
<xsl:call-template name="CA-graph">
  <xsl:with-param name="CA_entity" select="'program'"/>
  <xsl:with-param name="i" select="'3'"/>
</xsl:call-template>
<xsl:call-template name="CA-graph">
  <xsl:with-param name="CA_entity" select="'client_ip'"/>
  <xsl:with-param name="i" select="'4'"/>
</xsl:call-template>
<xsl:call-template name="CA-graph">
  <xsl:with-param name="CA_entity" select="'user_name'"/>
  <xsl:with-param name="i" select="'5'"/>
</xsl:call-template>
<xsl:call-template name="CA-graph">
  <xsl:with-param name="CA_entity" select="'application'"/>
  <xsl:with-param name="i" select="'6'"/>
</xsl:call-template>

simply I would like to write it in a simple and nice way instead of calling each time the template with different CA_entity and different i.
one restriction - since there is an if in the template CA-graph, it could be that some of the call template will not pass the if.

Thanks

 
Old July 18th, 2007, 03:42 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The best way to improve the efficiency of this code is probably to replace the expression /etd/entities/entity/data[@class=$CA_entity] with key('k', $CA_entity), having first declared

<xsl:key name="k" match="/etd/entities/entity/data" use="@class"/>

There's no reason to believe that the template calling should be inefficient, although of course that may be true for some implementations. You may not like the verbosity of the template calls, but that's a different matter. In 2.0 you can replace these with function calls.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 18th, 2007, 03:46 AM
Authorized User
 
Join Date: Jan 2006
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you very much.
if you say there is not efficency problem, so I dont see a reason to change.

Kfir






Similar Threads
Thread Thread Starter Forum Replies Last Post
Convering a String Array to an Integer array nkrust C# 9 November 17th, 2010 12:02 PM
Go from 2d Array to 1d array without defining type OneQuestion General .NET 1 January 10th, 2008 11:13 AM
calling one template in other template VijayKumar XSLT 3 September 15th, 2005 11:12 AM
error when sorting an Array of Array nancy VBScript 2 February 17th, 2005 12:57 PM
Passing php array values to javascript array gkrishna Pro PHP 0 November 6th, 2004 03:20 AM





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