use of org.apache.xml.dtm.ref.DTMTreeWalker in project robovm by robovm.
the class ElemCopyOf method execute.
/**
* The xsl:copy-of element can be used to insert a result tree
* fragment into the result tree, without first converting it to
* a string as xsl:value-of does (see [7.6.1 Generating Text with
* xsl:value-of]).
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException {
try {
XPathContext xctxt = transformer.getXPathContext();
int sourceNode = xctxt.getCurrentNode();
XObject value = m_selectExpression.execute(xctxt, sourceNode, this);
SerializationHandler handler = transformer.getSerializationHandler();
if (null != value) {
int type = value.getType();
String s;
switch(type) {
case XObject.CLASS_BOOLEAN:
case XObject.CLASS_NUMBER:
case XObject.CLASS_STRING:
s = value.str();
handler.characters(s.toCharArray(), 0, s.length());
break;
case XObject.CLASS_NODESET:
// System.out.println(value);
DTMIterator nl = value.iter();
// Copy the tree.
DTMTreeWalker tw = new TreeWalker2Result(transformer, handler);
int pos;
while (DTM.NULL != (pos = nl.nextNode())) {
DTM dtm = xctxt.getDTMManager().getDTM(pos);
short t = dtm.getNodeType(pos);
// generated, so we need to only walk the child nodes.
if (t == DTM.DOCUMENT_NODE) {
for (int child = dtm.getFirstChild(pos); child != DTM.NULL; child = dtm.getNextSibling(child)) {
tw.traverse(child);
}
} else if (t == DTM.ATTRIBUTE_NODE) {
SerializerUtils.addAttribute(handler, pos);
} else {
tw.traverse(pos);
}
}
// nl.detach();
break;
case XObject.CLASS_RTREEFRAG:
SerializerUtils.outputResultTreeFragment(handler, value, transformer.getXPathContext());
break;
default:
s = value.str();
handler.characters(s.toCharArray(), 0, s.length());
break;
}
}
// I don't think we want this. -sb
// if (transformer.getDebug())
// transformer.getTraceManager().fireSelectedEvent(sourceNode, this,
// "endSelect", m_selectExpression, value);
} catch (org.xml.sax.SAXException se) {
throw new TransformerException(se);
}
}
use of org.apache.xml.dtm.ref.DTMTreeWalker in project j2objc by google.
the class ElemCopyOf method execute.
/**
* The xsl:copy-of element can be used to insert a result tree
* fragment into the result tree, without first converting it to
* a string as xsl:value-of does (see [7.6.1 Generating Text with
* xsl:value-of]).
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException {
try {
XPathContext xctxt = transformer.getXPathContext();
int sourceNode = xctxt.getCurrentNode();
XObject value = m_selectExpression.execute(xctxt, sourceNode, this);
SerializationHandler handler = transformer.getSerializationHandler();
if (null != value) {
int type = value.getType();
String s;
switch(type) {
case XObject.CLASS_BOOLEAN:
case XObject.CLASS_NUMBER:
case XObject.CLASS_STRING:
s = value.str();
handler.characters(s.toCharArray(), 0, s.length());
break;
case XObject.CLASS_NODESET:
// System.out.println(value);
DTMIterator nl = value.iter();
// Copy the tree.
DTMTreeWalker tw = new TreeWalker2Result(transformer, handler);
int pos;
while (DTM.NULL != (pos = nl.nextNode())) {
DTM dtm = xctxt.getDTMManager().getDTM(pos);
short t = dtm.getNodeType(pos);
// generated, so we need to only walk the child nodes.
if (t == DTM.DOCUMENT_NODE) {
for (int child = dtm.getFirstChild(pos); child != DTM.NULL; child = dtm.getNextSibling(child)) {
tw.traverse(child);
}
} else if (t == DTM.ATTRIBUTE_NODE) {
SerializerUtils.addAttribute(handler, pos);
} else {
tw.traverse(pos);
}
}
// nl.detach();
break;
case XObject.CLASS_RTREEFRAG:
SerializerUtils.outputResultTreeFragment(handler, value, transformer.getXPathContext());
break;
default:
s = value.str();
handler.characters(s.toCharArray(), 0, s.length());
break;
}
}
// I don't think we want this. -sb
// if (transformer.getDebug())
// transformer.getTraceManager().fireSelectedEvent(sourceNode, this,
// "endSelect", m_selectExpression, value);
} catch (org.xml.sax.SAXException se) {
throw new TransformerException(se);
}
}
Aggregations