xsl-list
[Top] [All Lists]

RE: [xsl] for-each performance question

2009-01-26 14:08:08

If performance is important to you then

(a) you need to develop a measurement harness, so that you can try different
things out

(b) you need to consider aspects of the system other than your XSLT code.
The difference in cost between these four examples is likely to be tiny
(though you need to make measurements to be sure of this). You are much more
likely to get useful savings by:

  - caching of stylesheets and/or source documents

  - selecting your tree model carefully

  - thinking about how you invoke the XSLT processor, supply its input, and
consume its output

  - using a different XSLT processor.

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Josh Proctor [mailto:daslight110(_at_)gmail(_dot_)com] 
Sent: 26 January 2009 18:37
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] for-each performance question

I have a question concerning performance (or maybe best practice):

I am using cocoon 2.10, Xalan 2.7.0, and XSLT 1.

My xml looks like this:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<School>

        <Student>

                <Profile>

                        <LastName>Joe</LastName>

                        <FirstName>Smith</FirstName>

                        <Middle>L</Middle>

                        .

                </Profile>

        </Student>

        .

</School>

There are about 20 elements under profile, and only 1 student 
under HighSchoolAdmin.

I need to display all the profile information for the 
student. This should be very simple but I want to make sure 
it is as efficient as possible, as we could have a very large 
number of people hitting the system at once. The xml is not 
large but the number of users who will be looking at this 
within a small time frame is very large.

What would be best (or is there a better way):

Case 1:

A for-each "loop" which drills down to the parent node of the 
xml I want to display.

        <xsl:template match="/">

                <xsl:for-each select="School/Student/Profile">

                        <p>Last Name: <xsl:value-of 
select="LastName"/></p>

                        <p>First Name: <xsl:value-of 
select="FirstName"/></p>

                        <p>Middle Name: <xsl:value-of 
select="Middle"/></p>

                        ...

                </xsl:for-each>

        </xsl:template>

Case 2:

Applying a template which drills down to the parent node of 
the xml I want to display.

        <xsl:template match="/">

                <xsl:apply-templates select="School/Student/Profile"/>

        </xsl:template>



        <xsl:template match="Profile">

                <p>Last Name: <xsl:value-of select="LastName"/></p>

                <p>First Name: <xsl:value-of select="FirstName"/></p>

                <p>Middle Name: <xsl:value-of select="Middle"/></p>

                ...

        </xsl:template>

Case 3:

A variable with a tree fragment of the xml I want to display.

        <xsl:template match="/">

                <xsl:variable name="studentProfile"
select="School/Student/Profile"/>

                <p>Last Name: <xsl:value-of 
select="$studentProfile/LastName"/></p>

                <p>First Name: <xsl:value-of 
select="$studentProfile/FirstName"/></p>

                <p>Middle Name: <xsl:value-of 
select="$studentProfile/Middle"/></p>

                ...

        </xsl:template>

Case 4:

Use the XPath for each element I want to display.

        <xsl:template match="/">

                <p>Last Name: <xsl:value-of 
select="School/Student/Profile/LastName"/></p>

                <p>First Name: <xsl:value-of 
select="School/Student/Profile/FirstName"/></p>

                <p>Middle Name: <xsl:value-of 
select="School/Student/Profile/Middle"/></p>

                ...

        </xsl:template>

Thank you in advance for any help you can give me.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>