Copyright© 2008-2018 SiteVision AB, all rights reserved.
@Requireable(value="XSLTUtil") public interface XSLTUtil
Tip! This utility can be combined with OutputUtil
to produce modified versions of
the HTML produced by layouts or modules. Below is a simplistic example of how this can be done in server-side JavaScript.
var outputUtil = require('OutputUtil'), xsltUtil = require('XSLTUtil'), pageNode, pageContentNode, rawRenderResult, transformedRenderResult; pageNode = ... pageContentNode = ... rawRenderResult = outputUtil.getNodeOutput(pageNode, pageContentNode, outputUtil.CONTENT_TYPE_TEXT_HTML); transformedRenderResult = xsltUtil.transform(rawRenderResult, xsltUtil.getDefaultCleanHtmlTemplate());
An instance of the SiteVision class implementing this interface can be obtained via Utils.getXSLTUtil()
.
See Utils
for how to obtain an instance of the Utils
interface.
Modifier and Type | Method and Description |
---|---|
String |
getDefaultCleanHtmlTemplate()
Gets the default XSL template for cleanup of HTML sources.
|
String |
transform(String aSource,
Object aXslTemplate)
Transforms a HTML/XML source using a XSL template.
|
String getDefaultCleanHtmlTemplate()
The template strips all <div>'s, <spans>'s and removes all inline styling, classes and attributes that is not mandatory or needed for WCAG purposes.
Note! The template supports a sub-set of HTML elements (the presumed most commonly used elements). All unsupported elements are completely discarded (i.e. they will not be included at all in the transformation result).
String transform(String aSource, Object aXslTemplate) throws java.io.IOException, RepositoryException
Note! The contents of the XSL Template is always handled as UTF-8.
aSource
- the source that should be transformed, HTML, XHTML or XML. Must not be nullaXslTemplate
- the UTF-8 XSL template,
a sv:file Node, a sv:link Node that targets a sv:file, a char array or a CharSequence (typically a String). Must not be nulljava.io.IOException
- if the transformation fails (e.g. the aSource is really bad/interpretable HTML or aXslTemplate is invalid XSL)RepositoryException
- if aNode-operation on aXslTemplate failsSiteVision - Portal and Content Management Made Easy
SiteVision is an advanced Java enterprise portal product and a portlet container (JSR 286) that implements Java Content Repository (JSR 283).
Copyright© 2008-2018 SiteVision AB, all rights reserved.