public static String replaceVariables(ExpressionContext ctx,
String text) {
String value = text;
try
{
REMatch[] matches = variableRE.getAllMatches(text);
if( matches.length > 0 )
{
StringBuffer tmp = new StringBuffer();
for(int m = 0; m < matches.length; m ++)
{
String prefix = matches[m].toString(1);
String name = matches[m].toString(2);
String suffix = matches[m].toString(3);
QName varName = new QName(name);
XObject var = ctx.getVariableOrParam(varName);
tmp.append(prefix);
if( var != null )
tmp.append(var.toString());
tmp.append(suffix);
}
value = tmp.toString();
}
}
catch(TransformerException e)
{
e.printStackTrace();
}
return value;
}
This function replaces all occurrences of variable references ${...} with
the corresponding XSL variable. If no such variable is defined the variable
is replaced with an empty string. |