Example usage for org.dom4j.rule Stylesheet applyTemplates

List of usage examples for org.dom4j.rule Stylesheet applyTemplates

Introduction

In this page you can find the example usage for org.dom4j.rule Stylesheet applyTemplates.

Prototype

public void applyTemplates(Object input, XPath xpath, String mode) throws Exception 

Source Link

Document

Processes the result of the xpath expression in the given mode.

Usage

From source file:org.apache.commons.jelly.tags.jsl.ApplyTemplatesTag.java

License:Apache License

/** By default just evaluate the body */
public void doTag(XMLOutput output) throws JellyTagException {
    StylesheetTag tag = (StylesheetTag) findAncestorWithClass(StylesheetTag.class);
    if (tag == null) {
        throw new JellyTagException("<applyTemplates> tag must be inside a <stylesheet> tag");
    }/*from   ww  w .  j  ava2 s  . com*/
    Stylesheet stylesheet = tag.getStylesheet();

    XMLOutput oldOutput = tag.getStylesheetOutput();
    tag.setStylesheetOutput(output);

    Object source = tag.getXPathSource();
    // for some reason, these DOM4J methods only throw Exception
    try {
        if (select != null) {
            stylesheet.applyTemplates(source, select, mode);
        } else {
            stylesheet.applyTemplates(source, mode);
        }
    } catch (Exception e) {
        throw new JellyTagException(e);
    }

    tag.setStylesheetOutput(oldOutput);

    // #### should support MODE!!!

}