######################################################################## # $Header: /var/local/cvsroot/4Suite/Ft/Server/Common/SchematronStylesheet.py,v 1.8 2004/08/30 22:52:17 mbrown Exp $ """ Schematron stylesheet preprocessing Copyright 2004 Fourthought, Inc. (USA). Detailed license and copyright information: http://4suite.org/COPYRIGHT Project home, documentation, distributions: http://4suite.org/ """ import cPickle from Ft.Server import FTSS_URI_SCHEME from Ft.Server.Server.Drivers import FtssInputSource from Ft.Xml import Domlette, InputSource from Ft.Xml.Xslt import Processor, DomWriter, StylesheetReader STYLESHEET=""" In pattern ( ) : Warning: must not contain any child elements Warning: unrecognized element Warning: unrecognized element """ _STYLESHEET_INSTANCE = None def Init(): #Create the cpickled version of the schematron transformation global _STYLESHEET_INSTANCE r = StylesheetReader.StylesheetReader() isrc = InputSource.DefaultFactory.fromString(STYLESHEET, FTSS_URI_SCHEME + ':///schematron-stylesheet.xslt') doc = r.fromSrc(isrc) _STYLESHEET_INSTANCE = cPickle.dumps(doc.root) return def GetSchematronInstance(): if _STYLESHEET_INSTANCE is None: Init() return _STYLESHEET_INSTANCE def ParseSchematron(src, uri, driver, external=0): #Create a processor to create the meta sheet p = Processor.Processor() #Instantiate the schematron stylesheet schSt = cPickle.loads(GetSchematronInstance()).stylesheet p.appendStylesheetInstance(schSt) writer = DomWriter.DomWriter() #Create the meta stylesheet if external: isrc = InputSource.DefaultFactory.fromString(src, uri) else: isrc = FtssInputSource.FtssInputSourceFactory.fromString(src, uri, driver) p.run(isrc, writer=writer) doc = writer.getResult() reader = StylesheetReader.StylesheetReader() schema = reader.fromDocument(doc, uri) # Remove node cache for document('') to allow for pickling. # The resulting stylesheet doesn't use document('') anyway. del schema.root.sourceNodes[uri] return schema