def rendercnxml(source, prestyles=()): stylesheets = list(prestyles) stylesheets.append(CNXML_RENDER_XSL) params = {} params['wrapper'] = 0 doc = XMLService.parseString(source) result = XMLService.xsltPipeline(doc, stylesheets, **params) return result
def abstract_text(self): """The rendered abstract/summary text of content, by itself, stripped of markup. """ context = self.context source = getattr(context, 'getRawAbstract', None) source = source and source() or context.abstract if source: source = """<md:abstract xmlns="http://cnx.rice.edu/cnxml" xmlns:bib="http://bibtexml.sf.net/" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:md="http://cnx.rice.edu/mdml" xmlns:q="http://cnx.rice.edu/qml/1.0">%s</md:abstract>""" % source doc = XMLService.parseString(source) result = XMLService.xsltPipeline(doc, [CNXML_SEARCHABLE_XSL]) return result return ''
stylesheets = [stylesheet] ### for old CNXML (< 0.5) ### doctype = getattr(context, 'doctype', None) if doctype and doctype.find('0.5') == -1: from Products.CNXMLDocument import CNXML_UPGRADE_XSL stylesheets.insert(0, CNXML_UPGRADE_XSL) ### /upgrade ### # Parse the source and grab the namespaces doc = XMLService.parseString(source) sourceNs = XMLService.listDocNamespaces(doc) # Figure out our content types has_math = MATHML_NS in sourceNs params['doctype'], params['mimetype'], ns = context.content_type_decide( has_math=has_math) # Transform source result = XMLService.xsltPipeline(doc, stylesheets, **params) # Set content-type context.REQUEST.RESPONSE.setHeader('Content-Type', "%s; charset=utf-8" % params['mimetype']) # Prepend doctype header = context.xmlheader(params['doctype']) return header + '\n' + result
def testDoubleTransform(self): """xsltPipeline must correctly perform double transform""" doc = XMLService.parseDoc(noNS) self.assertEquals(XMLService.xsltPipeline(doc, ['step1.xsl', 'step2.xsl']), 'Success')
def testSingleTransform(self): """xsltPipeline must correctly perform single transform""" doc = XMLService.parseDoc(noNS) self.assertEquals(XMLService.xsltPipeline(doc, ['test.xsl']), 'Success')
def testEmptyPipeline(self): """xsltPipeline must serialize original doc if pipeline is empty""" doc = XMLService.parseDoc(noNS) self.assertEquals(XMLService.xsltPipeline(doc, []), '<tag>Hello</tag>')
if not stylesheet: stylesheet = CNXML_XSL stylesheets = [stylesheet] ### for old CNXML (< 0.5) ### doctype = getattr(context, 'doctype', None) if doctype and doctype.find('0.5') == -1: from Products.CNXMLDocument import CNXML_UPGRADE_XSL stylesheets.insert(0, CNXML_UPGRADE_XSL) ### /upgrade ### # Parse the source and grab the namespaces doc = XMLService.parseString(source) sourceNs = XMLService.listDocNamespaces(doc) # Figure out our content types has_math = MATHML_NS in sourceNs params['doctype'], params['mimetype'], ns = context.content_type_decide(has_math=has_math) # Transform source result = XMLService.xsltPipeline(doc, stylesheets, **params) # Set content-type context.REQUEST.RESPONSE.setHeader('Content-Type', "%s; charset=utf-8" % params['mimetype']) # Prepend doctype header = context.xmlheader(params['doctype']) return header+'\n'+result