/** * 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); } } } } }
/** * Combine the parent's namespaces with this namespace for fast processing, taking care to * reference the parent's namespace if this namespace adds nothing new. (Recursive method, walking * the elements depth-first, processing parents before children). Note that this method builds * m_prefixTable with aliased namespaces, *not* the original namespaces. * * @throws TransformerException */ public void resolvePrefixTables() throws TransformerException { // Always start with a fresh prefix table! m_prefixTable = null; // If we have declared declarations, then we look for // a parent that has namespace decls, and add them // to this element's decls. Otherwise we just point // to the parent that has decls. if (null != this.m_declaredPrefixes) { StylesheetRoot stylesheet = this.getStylesheetRoot(); // Add this element's declared prefixes to the // prefix table. int n = m_declaredPrefixes.size(); for (int i = 0; i < n; i++) { XMLNSDecl decl = (XMLNSDecl) m_declaredPrefixes.elementAt(i); String prefix = decl.getPrefix(); String uri = decl.getURI(); if (null == uri) uri = ""; boolean shouldExclude = excludeResultNSDecl(prefix, uri); // Create a new prefix table if one has not already been created. if (null == m_prefixTable) m_prefixTable = new Vector(); NamespaceAlias nsAlias = stylesheet.getNamespaceAliasComposed(uri); if (null != nsAlias) { // Should I leave the non-aliased element in the table as // an excluded element? // The exclusion should apply to the non-aliased prefix, so // we don't calculate it here. -sb // Use stylesheet prefix, as per xsl WG decl = new XMLNSDecl( nsAlias.getStylesheetPrefix(), nsAlias.getResultNamespace(), shouldExclude); } else decl = new XMLNSDecl(prefix, uri, shouldExclude); m_prefixTable.addElement(decl); } } ElemTemplateElement parent = this.getParentNodeElem(); if (null != parent) { // The prefix table of the parent should never be null! Vector prefixes = parent.m_prefixTable; if (null == m_prefixTable && !needToCheckExclude()) { // Nothing to combine, so just use parent's table! this.m_prefixTable = parent.m_prefixTable; } else { // Add the prefixes from the parent's prefix table. int n = prefixes.size(); for (int i = 0; i < n; i++) { XMLNSDecl decl = (XMLNSDecl) prefixes.elementAt(i); boolean shouldExclude = excludeResultNSDecl(decl.getPrefix(), decl.getURI()); if (shouldExclude != decl.getIsExcluded()) { decl = new XMLNSDecl(decl.getPrefix(), decl.getURI(), shouldExclude); } // m_prefixTable.addElement(decl); addOrReplaceDecls(decl); } } } else if (null == m_prefixTable) { // Must be stylesheet element without any result prefixes! m_prefixTable = new Vector(); } }