test_compiled_stylesheet.py :  » XML » 4Suite » 4Suite-XML-1.0.2 » test » Xml » Xslt » Core » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » XML » 4Suite 
4Suite » 4Suite XML 1.0.2 » test » Xml » Xslt » Core » test_compiled_stylesheet.py

import time

from Ft.Xml.Xslt import StylesheetCompilier

ADDRBOOK="""<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

  <xsl:template match="/">
    <HTML>
    <HEAD><TITLE>Address Book</TITLE>
    </HEAD>
    <BODY>
    <H1><xsl:text>Tabulate just the Names</xsl:text></H1>
    <TABLE><xsl:apply-templates/></TABLE>
    </BODY>
    </HTML>
  </xsl:template>

  <xsl:template match="ENTRY">
  <TR>
  <xsl:apply-templates select='NAME'/>
  </TR>
  </xsl:template>

  <xsl:template match="NAME">
    <TD ALIGN="CENTER">
      <B><xsl:apply-templates/></B>
    </TD>
  </xsl:template>

</xsl:stylesheet>
"""

ADDRBOOK_XML_1="""<?xml version = "1.0"?>
<!DOCTYPE ADDRBOOK SYSTEM "addr_book.dtd">
<ADDRBOOK xmlns:xlink="http://www.w3.org/XML/XLink/0.9">"""
ADDRBOOK_XML_ENTRY="""
  <ENTRY ID="vz">
    <NAME>Vasia Zhugenev</NAME>
    <ADDRESS>2000 Disaster Plaza</ADDRESS>
    <PHONENUM DESC="Work">000-987-6543</PHONENUM>
    <PHONENUM DESC="Cell">000-000-0000</PHONENUM>
    <EMAIL>vxz@magog.ru</EMAIL>
  </ENTRY>"""
ADDRBOOK_XML_2="""
</ADDRBOOK>
"""

ERASTOTHENES_SOURCE="""<dummy/>"""
ERASTOTHENES_FILE="borrowed/erastothenes.xslt"


def test():

    #Test generating a file and running it
    #Test a simple addrbook

    #Build a ADDRBOOK xml file
    print "Address Book"
    src = ADDRBOOK_XML_1 + (ADDRBOOK_XML_ENTRY*5000) + ADDRBOOK_XML_2
    s = time.time()
    StylesheetCompilier.CompileString(ADDRBOOK,outFileName='addrbook')
    e = time.time()
    t = e - s
    print "Compile Time: %f" % (t)

    import addrbook
    st = addrbook.Stylesheet()
    s = time.time()
    st.executeString(src)
    e = time.time()
    cTime = e - s
    print "Compile Time: %f" % (cTime)

    from Ft.Xml.Xslt import Processor
    p = Processor.Processor()
    p.appendStylesheetString(ADDRBOOK)
    s = time.time()
    p.runString(src)
    e = time.time()
    pTime = e - s
    print "Processor Time: %f" % (pTime)
    print "Difference %f" % (pTime - cTime)
    print "Increase %f" % (100.0*(pTime - cTime)/pTime)


def test2():

    #Run a larger document (RDF API document)
    print "RDF API"
    srcUri = "/usr/doc/4Suite-0.10.1/docs/xml/4RDF.api"
    styUri = "/usr/local/lib/xslt/api.xslt"
    s = time.time()
    StylesheetCompilier.CompileUri(styUri,outFileName='api',baseUri='/usr/local/lib/xslt/')
    e = time.time()
    t = e - s
    print "Compile Time: %f" % (t)
    




    #Run The Sieve of Erastothenes
    StylesheetCompilier.CompileUri(ERASTOTHENES_FILE,outFileName='erastonthenes')



    



if __name__ == '__main__':
    #test()
    test2()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.