37 |
|
|
38 |
package gnu.xml.transform; |
package gnu.xml.transform; |
39 |
|
|
40 |
|
import java.util.Collection; |
41 |
|
import java.util.Iterator; |
42 |
import javax.xml.namespace.QName; |
import javax.xml.namespace.QName; |
43 |
import javax.xml.transform.TransformerException; |
import javax.xml.transform.TransformerException; |
44 |
import org.w3c.dom.Document; |
import org.w3c.dom.Document; |
58 |
final Expr select; |
final Expr select; |
59 |
final boolean disableOutputEscaping; |
final boolean disableOutputEscaping; |
60 |
|
|
61 |
ValueOfNode(TemplateNode children, TemplateNode next, Expr select, |
ValueOfNode(Expr select, boolean disableOutputEscaping) |
|
boolean disableOutputEscaping) |
|
62 |
{ |
{ |
|
super(children, next); |
|
63 |
this.select = select; |
this.select = select; |
64 |
this.disableOutputEscaping = disableOutputEscaping; |
this.disableOutputEscaping = disableOutputEscaping; |
65 |
} |
} |
66 |
|
|
67 |
TemplateNode clone(Stylesheet stylesheet) |
TemplateNode clone(Stylesheet stylesheet) |
68 |
{ |
{ |
69 |
return new ValueOfNode((children == null) ? null : |
TemplateNode ret = new ValueOfNode(select.clone(stylesheet), |
70 |
children.clone(stylesheet), |
disableOutputEscaping); |
71 |
(next == null) ? null : |
if (children != null) |
72 |
next.clone(stylesheet), |
{ |
73 |
select.clone(stylesheet), |
ret.children = children.clone(stylesheet); |
74 |
disableOutputEscaping); |
} |
75 |
|
if (next != null) |
76 |
|
{ |
77 |
|
ret.next = next.clone(stylesheet); |
78 |
|
} |
79 |
|
return ret; |
80 |
} |
} |
81 |
|
|
82 |
void doApply(Stylesheet stylesheet, QName mode, |
void doApply(Stylesheet stylesheet, QName mode, |
85 |
throws TransformerException |
throws TransformerException |
86 |
{ |
{ |
87 |
Object ret = select.evaluate(context, pos, len); |
Object ret = select.evaluate(context, pos, len); |
88 |
String value = Expr._string(context, ret); |
String value; |
89 |
//System.err.println("value-of: "+context+" "+ select + " -> "+ value); |
if (ret instanceof Collection) |
90 |
|
{ |
91 |
|
StringBuffer buf = new StringBuffer(); |
92 |
|
for (Iterator i = ((Collection) ret).iterator(); i.hasNext(); ) |
93 |
|
{ |
94 |
|
Node node = (Node) i.next(); |
95 |
|
buf.append(Expr.stringValue(node)); |
96 |
|
} |
97 |
|
value = buf.toString(); |
98 |
|
} |
99 |
|
else |
100 |
|
{ |
101 |
|
value = Expr._string(context, ret); |
102 |
|
} |
103 |
|
/*if (stylesheet.debug) |
104 |
|
{ |
105 |
|
System.err.println("value-of: "+context+" "+ select + " -> "+ value); |
106 |
|
}*/ |
107 |
if (value != null && value.length() > 0) |
if (value != null && value.length() > 0) |
108 |
{ |
{ |
109 |
Document doc = (parent instanceof Document) ? |
Document doc = (parent instanceof Document) ? |