/** * Obtains the XSLT stylesheet at the given ClassPathURI, using the {@link StylesheetCache} * (if set) to cache stylesheets for efficiency. * * @param classPathUri location of the XSLT stylesheet in the ClassPath, following the * URI scheme in {@link ClassPathURIResolver}. * * @return compiled XSLT stylesheet. */ public Templates getCompiledStylesheet(final String classPathUri) { return getCompiledStylesheet(classPathUri, false); }
serializer = getCompiledStylesheet(stylesheetUris.get(0), requiresXSLT20).newTransformer();
private Document fixMaximaMathmlOutput(final Document document) { final Document resultDocument = XMLUtilities.createNSAwareDocumentBuilder().newDocument(); try { /* Create required XSLT */ final Templates upconverterStylesheet = stylesheetManager.getCompiledStylesheet(FIXER_XSLT_URI); final Transformer upconverter = upconverterStylesheet.newTransformer(); /* Do the transform */ upconverter.transform(new DOMSource(document), new DOMResult(resultDocument)); } catch (final TransformerException e) { throw new SnuggleRuntimeException("Fixing failed", e); } return resultDocument; }
public Document downConvertDOM(Document document) { /* If inlining CSS, create a document to hold the name/value pairs as described in * buildCSSPropertiesDocument(). Otherwise, we'll create an empty one to indicate * that nothing should be inlined */ Document cssPropertiesDocument = XMLUtilities.createNSAwareDocumentBuilder().newDocument(); if (cssProperties!=null) { buildCSSPropertiesDocument(cssPropertiesDocument, cssProperties); } /* Create URI Resolver to let the XSLT get at this document */ CSSPropertiesURIResolver uriResolver = new CSSPropertiesURIResolver(cssPropertiesDocument); /* Run the conversion XSLT */ Templates templates = stylesheetManager.getCompiledStylesheet(Globals.MATHML_TO_XHTML_XSL_RESOURCE_NAME); Document result = XMLUtilities.createNSAwareDocumentBuilder().newDocument(); try { Transformer transformer = templates.newTransformer(); transformer.setURIResolver(uriResolver); transformer.transform(new DOMSource(document), new DOMResult(result)); } catch (Exception e) { throw new SnuggleRuntimeException("Unexpected Exception down-converting DOM", e); } return result; }