The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tree::Transform::XSLTish::Transformer - transformer class for Tree::Transform::XSLTish

METHODS

new

  $trans=Tree::Transform::XSLTish::Transformer->new(
    rules_package => 'Some::Package',
    engine => $engine_instance,
  );

You usually don't call this constructor directly, but instead use the new function exported by Tree::Transform::XSLTish, which passes the correct rules_package automatically.

If you don't specify an engine, it will be constructed using the class or factory declared in the rules package; if you didn't declare anything, it will be an instance of Tree::XPathEngine.

transform

  @results=$trans->transform($tree);

When you call this function on a tree, the transformer will transform it according to your rules and to the XSLT processing model.

$trans->transform($node) is equivalent to $trans->apply_rules($trans->engine->findnodes('/',$node)).

Always call this method in list context.

apply_rules

   $trans->apply_rules(@nodes);

Just like apply-rules in XSLT, this function will apply the rules to the specified nodes, or to the children of the current node if none are passed, and return all the results in a single list.

This will die if there are no matching rules, or if there are more than one matching rule with highest priority.

Always call this method in list context.

call_rule

  $trans->call_rule('rule-name');

This fuction will apply the named rule to the current node, and return the result.

This will die if there is no rule with the given name.

Always call this method in list context.

it

  $current_node = $trans->it;

Inside a rule, this fuction will return the node to which the rule is being applied.

INTERNAL FUNCTIONS

These functions should not be called from outside this module.

find_rule

For each package in the linearized inheritance chain of the rules package on which this transformer has been instantiated, calls find_rule_in_package and returns the first defined result.

find_rule_in_package

Gets all the rules having a match attribute, filters those for which rule_matches returns true, sorts them by priority, and returns the one with the highest priority.

Dies if there is more than one rule with the highest priority; returns undef if there are no matching rules.

find_rule_by_name

For each package in the linearized inheritance chain of the rules package on which this transformer has been instantiated, calls find_rule_by_name_in_package and returns the first defined result.

find_rule_by_name_in_package

Returns the rule with the given name, if any; returns undef otherwise.

rule_matches

Evaluates the match XPath expression in a sequence of contexts, to see if the current node appears in the resulting node-set. If it does, returns true; if there is no such context, returns false.

The first context is the current node; following contexts are each the parent node of the previous one.

NOTE: to check whether a node appears in a node-set, we either use the isSameNode method, or check the stringifications for equality.

AUTHOR

Gianni Ceccarelli <dakkar@thenautilus.net>