Example usage for org.dom4j.rule Stylesheet Stylesheet

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

Introduction

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

Prototype

public Stylesheet() 

Source Link

Document

Creates a new empty stylesheet.

Usage

From source file:org.dom4j.samples.rule.SongFilter.java

License:Open Source License

public Document filtering(org.dom4j.Document doc) throws Exception {
    Element resultRoot = DocumentHelper.createElement("result");
    this.resultDoc = DocumentHelper.createDocument(resultRoot);

    Rule songElementRule = new Rule();
    songElementRule.setPattern(DocumentHelper.createPattern("/Songs/song/mp3/id3"));
    songElementRule.setAction(new SongElementBuilder());

    Rule titleTextNodeFilter = new Rule();
    titleTextNodeFilter.setPattern(DocumentHelper.createPattern("/Songs/song/mp3/id3/title"));
    titleTextNodeFilter.setAction(new NodeTextFilter());

    this.style = new Stylesheet();
    this.style.addRule(songElementRule);
    this.style.addRule(titleTextNodeFilter);

    style.run(doc);//  w  ww  .  j  ava 2 s  .  co  m

    return this.resultDoc;
}