Example #1
0
    def send_xsl(self, xml, xsl):
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.end_headers()
        sheetfile = open(xsl, "r")
        sheet = sheetfile.read()

        proc = Processor()
        proc.appendStylesheetString(sheet)
        self.wfile.write(proc.runString(xml))
Example #2
0
    def send_xsl(self,xml,xsl):
        self.send_response(200)
        self.send_header("Content-type", "text/html") 
        self.end_headers() 
        sheetfile = open(xsl,"r")
        sheet = sheetfile.read()

        proc = Processor()
        proc.appendStylesheetString(sheet)
        self.wfile.write(proc.runString(xml))
Example #3
0
def get_processor( req, name ):
   dir = os.path.split( req.filename )[0]
   fn = os.path.join( dir, name + ".xsl" )
   s = os.stat( fn )
   mtime = s[stat.ST_MTIME]
   if P_CACHE.has_key(fn):
      if mtime == P_CACHE[fn][0]:
         return P_CACHE[fn][1]
   #
   p = Processor()
   p.registerExtensionModules( ["stylex"] )
   p.appendStylesheetUri( fn )
   P_CACHE[fn] = ( mtime, p )
   return p
Example #4
0
def Run(argv):
    (validate_flag, out_file, ignore_pis, top_level_params, stylesheets,
     source, trace_on_error, command_line_error) = ParseCommandLine(argv)

    out_file = out_file and open(out_file, 'w') or sys.stdout

    processor = Processor()
    import os
    try:
        from Ft.Lib import pDomlette
        BETA_DOMLETTE = os.environ.get("BETA_DOMLETTE")
        if BETA_DOMLETTE and not validate_flag:
            from Ft.Lib import cDomlette
            g_readerClass = cDomlette.RawExpatReader
            reader = cDomlette.RawExpatReader()
        elif validate_flag:
            reader = pDomlette.SaxReader(validate=1)
        else:
            reader = pDomlette.PyExpatReader()
    except ImportError:
        import minisupport
        reader = minisupport.MinidomReader(validate_flag)

    try:
        processor.setDocumentReader(reader)
        for sty in stylesheets:
            processor.appendStylesheetUri(sty)
        if source == '-':
            result = processor.runStream(sys.stdin,
                                         ignore_pis,
                                         topLevelParams=top_level_params)
        else:
            result = processor.runUri(source,
                                      ignore_pis,
                                      topLevelParams=top_level_params)
    except XsltException, e:
        s = cStringIO.StringIO()
        traceback.print_exc(1000, s)
        sys.stderr.write(s.getvalue())
        sys.stderr.write(str(e) + '\n')
        sys.exit(-1)
Example #5
0
def get_processor(req, name):
    dir = os.path.split(req.filename)[0]
    fn = os.path.join(dir, name + ".xsl")
    s = os.stat(fn)
    mtime = s[stat.ST_MTIME]
    if P_CACHE.has_key(fn):
        if mtime == P_CACHE[fn][0]:
            return P_CACHE[fn][1]
    #
    p = Processor()
    p.registerExtensionModules(["stylex"])
    p.appendStylesheetUri(fn)
    P_CACHE[fn] = (mtime, p)
    return p
Example #6
0
def Run(argv):
    (validate_flag, out_file, ignore_pis, top_level_params,
     stylesheets, source, trace_on_error, command_line_error) = ParseCommandLine(argv)

    out_file = out_file and open(out_file, 'w') or sys.stdout

    processor = Processor()
    import os
    try:
        from Ft.Lib import pDomlette
        BETA_DOMLETTE = os.environ.get("BETA_DOMLETTE")
        if BETA_DOMLETTE and not validate_flag:
            from Ft.Lib import cDomlette
            g_readerClass = cDomlette.RawExpatReader
            reader = cDomlette.RawExpatReader()
        elif validate_flag:
            reader = pDomlette.SaxReader(validate=1)
        else:
            reader = pDomlette.PyExpatReader()
    except ImportError:
        import minisupport
        reader = minisupport.MinidomReader(validate_flag)

    try:
        processor.setDocumentReader(reader)
        for sty in stylesheets:
            processor.appendStylesheetUri(sty)
        if source == '-':
            result = processor.runStream(sys.stdin, ignore_pis,
                                      topLevelParams=top_level_params)
        else:
            result = processor.runUri(source, ignore_pis,
                                      topLevelParams=top_level_params)
    except XsltException, e:
        s = cStringIO.StringIO()
        traceback.print_exc(1000, s)
        sys.stderr.write(s.getvalue())
        sys.stderr.write(str(e) + '\n')
        sys.exit(-1)
#!/usr/bin/python
#

from xml.xslt.Processor import Processor

xsltproc = Processor()

xsltproc.appendStylesheetUri(
    "file:///home/t0rt00se/Travail/SILR3/pTrans/testset/persons_to_xhtml_list.xsl"
)
html = xsltproc.run(DefaultFactory.fromUri("persons.xml"))
Example #8
0
        navigation = '<a href="%s">Index</a>' % pagename
        pathlen = modname.count('.')
        if pathlen:
            navigation = navigation + ' | '
            modparts = modname.split('.')
            for pathidx in range(pathlen):
                path = '.'.join(modparts[:pathidx + 1])
                navigation = navigation + '<a href="%s?module=%s">%s</a>' % (
                    pagename, path, modparts[pathidx])
                if pathidx < pathlen:
                    navigation = navigation + '.'
        navigation = navigation + '<hr size="1">'
    else:
        # generate index
        xmlstr = xmldoc.xml.document(None, encoding=config.charset)
        navigation = ''

    processor = Processor()
    processor.appendStylesheetFile(xslfile)
    try:
        result = processor.runString(xmlstr,
                                     topLevelParams={
                                         'uri-prefix': pagename + "?module=",
                                         'uri-suffix': "",
                                     })
    except:
        print wikiutil.escape(xmlstr)
        raise

    return navigation + result
Example #9
0
        if pathlen:
            navigation = navigation + ' | '
            modparts = modname.split('.')
            for pathidx in range(pathlen):
                path = '.'.join(modparts[:pathidx+1])
                navigation = navigation + '<a href="%s?module=%s">%s</a>' % (
                    pagename, path, modparts[pathidx])
                if pathidx < pathlen:
                    navigation = navigation + '.'
        navigation = navigation + '<hr size="1">'
    else:
        # generate index
        xmlstr = xmldoc.xml.document(None, encoding=config.charset)
        navigation = ''

    processor = Processor()
    processor.appendStylesheetFile(xslfile)
    try:
        result = processor.runString(xmlstr,
            topLevelParams={
                'uri-prefix': pagename + "?module=",
                'uri-suffix': "",
            }
        )
    except:
        print wikiutil.escape(xmlstr)
        raise

    return navigation + result

Example #10
0
            return StylesheetReader.fromUri(self, uri, baseUri, ownerDoc,
                                            stripElements)


if __name__ == "__main__":
    # the sample stylesheet repository
    internal_stylesheets = {
        'second-author.xsl':
        """
            <person xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0">
            <xsl:value-of select="books/book/author[2]"/>
            </person>
        """
    }

    # the sample document, referring to an "internal" stylesheet
    xmldoc = """
      <?xml-stylesheet href="internal:second-author.xsl" type="text/xml"?>
      <books>
        <book title="Python Essential Reference">
          <author>David M. Beazley</author>
          <author>Guido van Rossum</author>
        </book>
      </books>
    """

    # create XSLT processor and run it
    processor = Processor()
    processor.setStylesheetReader(StylesheetFromDict(internal_stylesheets))
    print processor.runString(xmldoc)
Example #11
0
def convert_spread():
    xsltproc = Processor()
    xsltproc.appendStylsheetUri("templ.xsl")
    html = xsltproc.runUri("temp.xml")
Example #12
0
#!/usr/bin/python
#

from xml.xslt.Processor import Processor

xsltproc = Processor()

xsltproc.appendStylesheetUri("file:///home/t0rt00se/Travail/SILR3/pTrans/testset/persons_to_xhtml_list.xsl")
html = xsltproc.run(DefaultFactory.fromUri("persons.xml"))