/** * Set the "xml:space" attribute. A text node is preserved if an ancestor element of the text node * has an xml:space attribute with a value of preserve, and no closer ancestor element has * xml:space with a value of default. * * @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a> * @see <a href="http://www.w3.org/TR/xslt#section-Creating-Text">section-Creating-Text in XSLT * Specification</a> * @param avt Enumerated value, either Constants.ATTRVAL_PRESERVE or Constants.ATTRVAL_STRIP. */ public void setXmlSpace(AVT avt) { // This function is a bit-o-hack, I guess... addLiteralResultAttribute(avt); String val = avt.getSimpleString(); if (val.equals("default")) { super.setXmlSpace(Constants.ATTRVAL_STRIP); } else if (val.equals("preserve")) { super.setXmlSpace(Constants.ATTRVAL_PRESERVE); } // else maybe it's a real AVT, so we can't resolve it at this time. }
/** * Call the children visitors. * * @param visitor The visitor whose appropriate method will be called. */ protected void callChildVisitors(XSLTVisitor visitor, boolean callAttrs) { if (callAttrs && null != m_avts) { int nAttrs = m_avts.size(); for (int i = (nAttrs - 1); i >= 0; i--) { AVT avt = (AVT) m_avts.get(i); avt.callVisitors(visitor); } } super.callChildVisitors(visitor, callAttrs); }
/** * This function is called after everything else has been recomposed, and allows the template to * set remaining values that may be based on some other property that depends on recomposition. */ public void compose(StylesheetRoot sroot) throws TransformerException { super.compose(sroot); StylesheetRoot.ComposeState cstate = sroot.getComposeState(); java.util.Vector vnames = cstate.getVariableNames(); if (null != m_avts) { int nAttrs = m_avts.size(); for (int i = (nAttrs - 1); i >= 0; i--) { AVT avt = (AVT) m_avts.get(i); avt.fixupVariables(vnames, cstate.getGlobalsSize()); } } }
/** * Augment resolvePrefixTables, resolving the namespace aliases once the superclass has resolved * the tables. * * @throws TransformerException */ public void resolvePrefixTables() throws TransformerException { super.resolvePrefixTables(); StylesheetRoot stylesheet = getStylesheetRoot(); if ((null != m_namespace) && (m_namespace.length() > 0)) { NamespaceAlias nsa = stylesheet.getNamespaceAliasComposed(m_namespace); if (null != nsa) { m_namespace = nsa.getResultNamespace(); // String resultPrefix = nsa.getResultPrefix(); String resultPrefix = nsa.getStylesheetPrefix(); // As per xsl WG, Mike Kay if ((null != resultPrefix) && (resultPrefix.length() > 0)) m_rawName = resultPrefix + ":" + m_localName; else m_rawName = m_localName; } } if (null != m_avts) { int n = m_avts.size(); for (int i = 0; i < n; i++) { AVT avt = (AVT) m_avts.get(i); // Should this stuff be a method on AVT? String ns = avt.getURI(); if ((null != ns) && (ns.length() > 0)) { NamespaceAlias nsa = stylesheet.getNamespaceAliasComposed(m_namespace); // %REVIEW% ns? if (null != nsa) { String namespace = nsa.getResultNamespace(); // String resultPrefix = nsa.getResultPrefix(); String resultPrefix = nsa.getStylesheetPrefix(); // As per XSL WG String rawName = avt.getName(); if ((null != resultPrefix) && (resultPrefix.length() > 0)) rawName = resultPrefix + ":" + rawName; avt.setURI(namespace); avt.setRawName(rawName); } } } } }
/** * Apply a set of attributes to the element. * * @param transformer non-null reference to the the current transform-time state. * @throws TransformerException */ public void execute(TransformerImpl transformer) throws TransformerException { if (transformer.isRecursiveAttrSet(this)) { throw new TransformerException( XSLMessages.createMessage( XSLTErrorResources.ER_XSLATTRSET_USED_ITSELF, new Object[] {m_qname.getLocalPart()})); // "xsl:attribute-set '"+m_qname.m_localpart+ } transformer.pushElemAttributeSet(this); super.execute(transformer); ElemAttribute attr = (ElemAttribute) getFirstChildElem(); while (null != attr) { attr.execute(transformer); attr = (ElemAttribute) attr.getNextSiblingElem(); } transformer.popElemAttributeSet(); }
/** * Copy a Literal Result Element into the Result tree, copy the non-excluded namespace attributes, * copy the attributes not of the XSLT namespace, and execute the children of the LRE. * * @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT * Specification</a> * @param transformer non-null reference to the the current transform-time state. * @throws TransformerException */ public void execute(TransformerImpl transformer) throws TransformerException { SerializationHandler rhandler = transformer.getSerializationHandler(); try { // JJK Bugzilla 3464, test namespace85 -- make sure LRE's // namespace is asserted even if default, since xsl:element // may have changed the context. rhandler.startPrefixMapping(getPrefix(), getNamespace()); // Add namespace declarations. executeNSDecls(transformer); rhandler.startElement(getNamespace(), getLocalName(), getRawName()); } catch (SAXException se) { throw new TransformerException(se); } /* * If we make it to here we have done a successful startElement() * we will do an endElement() call for balance, no matter what happens * in the middle. */ // tException remembers if we had an exception "in the middle" TransformerException tException = null; try { // Process any possible attributes from xsl:use-attribute-sets first super.execute(transformer); // xsl:version, excludeResultPrefixes??? // Process the list of avts next if (null != m_avts) { int nAttrs = m_avts.size(); for (int i = (nAttrs - 1); i >= 0; i--) { AVT avt = (AVT) m_avts.get(i); XPathContext xctxt = transformer.getXPathContext(); int sourceNode = xctxt.getCurrentNode(); String stringedValue = avt.evaluate(xctxt, sourceNode, this); if (null != stringedValue) { // Important Note: I'm not going to check for excluded namespace // prefixes here. It seems like it's too expensive, and I'm not // even sure this is right. But I could be wrong, so this needs // to be tested against other implementations. rhandler.addAttribute( avt.getURI(), avt.getName(), avt.getRawName(), "CDATA", stringedValue, false); } } // end for } // Now process all the elements in this subtree // TODO: Process m_extensionElementPrefixes && m_attributeSetsNames transformer.executeChildTemplates(this, true); } catch (TransformerException te) { // thrown in finally to prevent original exception consumed by subsequent exceptions tException = te; } catch (SAXException se) { tException = new TransformerException(se); } try { /* we need to do this endElement() to balance the * successful startElement() call even if * there was an exception in the middle. * Otherwise an exception in the middle could cause a system to hang. */ rhandler.endElement(getNamespace(), getLocalName(), getRawName()); } catch (SAXException se) { /* we did call endElement(). If thee was an exception * in the middle throw that one, otherwise if there * was an exception from endElement() throw that one. */ if (tException != null) throw tException; else throw new TransformerException(se); } /* If an exception was thrown in the middle but not with startElement() or * or endElement() then its time to let it percolate. */ if (tException != null) throw tException; unexecuteNSDecls(transformer); // JJK Bugzilla 3464, test namespace85 -- balance explicit start. try { rhandler.endPrefixMapping(getPrefix()); } catch (SAXException se) { throw new TransformerException(se); } }