throws TransformerException, TransformerConfigurationException,
SAXException, IOException, FileNotFoundException
{
try
{
SAXTransformerFactory saxTFactory = (SAXTransformerFactory) TransformerFactory.newInstance();
// XML doc to transform.
String source = elem.getAttribute("source",
context.getContextNode(),
context.getTransformer());
TransformerImpl transImpl = context.getTransformer();
//Base URI for input doc, so base for relative URI to XML doc to transform.
String baseURLOfSource = transImpl.getBaseURLOfSource();
// Absolute URI for XML doc to transform.
String absSourceURL = SystemIDResolver.getAbsoluteURI(source, baseURLOfSource);
// Transformation target
String target = elem.getAttribute("target",
context.getContextNode(),
context.getTransformer());
XPathContext xctxt = context.getTransformer().getXPathContext();
int xt = xctxt.getDTMHandleFromNode(context.getContextNode());
// Get System Id for stylesheet; to be used to resolve URIs to other stylesheets.
String sysId = elem.getSystemId();
NodeList ssNodes = null;
NodeList paramNodes = null;
Node ssNode = null;
Node paramNode = null;
if (elem.hasChildNodes())
{
ssNodes = elem.getChildNodes();
// Vector to contain TransformerHandler for each stylesheet.
Vector vTHandler = new Vector(ssNodes.getLength());
// The child nodes of an extension element node are instances of
// ElemLiteralResult, which requires does not fully support the standard
// Node interface. Accordingly, some special handling is required (see below)
// to get attribute values.
for (int i = 0; i < ssNodes.getLength(); i++)
{
ssNode = ssNodes.item(i);
if (ssNode.getNodeType() == ssNode.ELEMENT_NODE
&& ((Element)ssNode).getTagName().equals("stylesheet")
&& ssNode instanceof ElemLiteralResult)
{
AVT avt = ((ElemLiteralResult)ssNode).getLiteralResultAttribute("href");
String href = avt.evaluate(xctxt,xt, elem);
String absURI = SystemIDResolver.getAbsoluteURI(href, sysId);
Templates tmpl = saxTFactory.newTemplates(new StreamSource(absURI));
TransformerHandler tHandler = saxTFactory.newTransformerHandler(tmpl);
Transformer trans = tHandler.getTransformer();
// AddTransformerHandler to vector
vTHandler.addElement(tHandler);