<core:smooks filterSourceOn="#document">
<core:config>
<smooks-resource-list>
<core:rewrite>
<resource-config selector="record">
<resource>org.smooks.examples.pipeline.MyCounter</resource>
</resource-config>
<core:echo/>
</core:rewrite>
<resource-config selector="record">
<resource>org.smooks.examples.pipeline.IncrementCounter</resource>
</resource-config>
<dfdl:unparser schemaUri="my-schema.dfdl.xsd" unparseOnNode="*"/>
</smooks-resource-list>
</core:config>
</core:smooks>
public class IncrementCounter implements BeforeVisitor {
@Override
public void visitBefore(Element element, ExecutionContext executionContext) {
Integer counter = (Integer) executionContext.getBeanContext().getBean("counter");
if (counter != null) {
executionContext.getBeanContext().addBean("counter", counter + 1);
} else {
executionContext.getBeanContext().addBean("counter", 1);
}
}
}
public class MyCounter implements AfterVisitor {
@Override
public void visitAfter(Element element, ExecutionContext executionContext) {
try {
Stream.out(executionContext).write(XmlUtils.serialize(element) + String.format("<counter>%s</counter>", executionContext.getBeanContext().getBean("counter")));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
--
You received this message because you are subscribed to the Google Groups "Smooks Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to smooks-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/smooks-user/abc5b8f9-d85b-4442-9161-44e848ef64b3n%40googlegroups.com.