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 October 4th, 2007, 08:25 AM
Authorized User
 
Join Date: Oct 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is there any way to make it faster...bcoz its taking too long (for a 1.25 MB xml file taking forever). I do understand that for each n every node() it's looking for template match but is there any better.faster way to do it.

Thanks,
Trishla

 
Old October 4th, 2007, 09:09 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Can you show the XSLT you ended up using, I don't see why it should take that long? How many book elements are in the real XML?

--

Joe (Microsoft MVP - XML)
 
Old October 4th, 2007, 11:09 AM
Authorized User
 
Join Date: Oct 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The book structure is just a simlified example to show what I'm doing but anyway it has around 2500-3000 <ook>and many more element inside <book>node, which I purposely did not put here.

Also, I'm doing some more trimming of spaces apart from what I stated as condition here like removing whitespace node with <xsl:strip-space elements="."> and removing preceding and trailing spaces with normalize-space function.

Here is the stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="node()" mode="strip-all">
        <xsl:copy>
            <xsl:apply-templates mode="strip-all"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="node()" mode="strip-some">
        <xsl:copy>
            <xsl:apply-templates mode="strip-some"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="node()" mode="strip-quad">
        <xsl:copy>
            <xsl:apply-templates mode="strip-quad"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="book[topic='Biology']">
        <xsl:copy>
            <xsl:apply-templates mode="strip-quad"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="text()" mode="strip-quad">
    <xsl:value-of select="normalize-space()"></xsl:value-of>

    </xsl:template>


    <xsl:template match="book[topic='programming'] | book[topic='Computers']">
        <xsl:copy>
            <xsl:apply-templates mode="strip-all"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="text()" mode="strip-all">
    <xsl:strip-space elements="."></xsl:strip-space>
        <xsl:value-of select="translate(normalize-space(.), ' ', '')"/>
    </xsl:template>
    <xsl:template match="book[topic='Literature']">
        <xsl:copy>
            <xsl:apply-templates mode="strip-some"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="text()[not(contains(preceding::text()[1], 'Lang'))]" mode="strip-some">
        <xsl:value-of select="translate(., ' ', '')"/>
    </xsl:template>
</xsl:stylesheet>



 
Old October 4th, 2007, 11:46 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well that looks a bit dodgy, xsl:strip-space elements shouldn't be inside a template. Can you email me the actual books XML? You can send it to joefawcett at hotmail dot com.

--

Joe (Microsoft MVP - XML)
 
Old October 4th, 2007, 12:02 PM
Authorized User
 
Join Date: Oct 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I even try to run it without <xsl:strip-element> and it took same time which is over 9 minutes.

 
Old October 4th, 2007, 12:04 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well if you email the books data as I suggested I'll run it on my machine.

--

Joe (Microsoft MVP - XML)
 
Old October 4th, 2007, 05:35 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I can only surmise that you are using a processor with a very naive implementation of

preceding::text()[1]

Try a different XSLT processor, and it may go 100 times faster.

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 keep leading and trailing whitespaces? 2BOrNot2B XSLT 2 October 31st, 2008 11:35 AM
preserving whitespaces in attribute values? kaps77 XSLT 7 August 13th, 2007 11:48 AM
Preserved leading and tailing whitespaces problem ivan603 XML 0 February 7th, 2006 10:18 PM
checking for any whitespaces furia_cross Javascript How-To 1 September 7th, 2005 05:58 PM
Where are my whitespaces going? dimondwoof XSLT 3 July 17th, 2003 08:02 AM





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