code: public void setTemplate(ElemTemplate template)
    {
      XPath matchXPath = template.getMatch();
      
      if (null == template.getName() && null == matchXPath)
      {  
        template.error(XSLTErrorResources.ER_NEED_NAME_OR_MATCH_ATTRIB,
            new Object[]{ "xsl:template" });
      }
      
      if (null != template.getName())
      {
        ElemTemplate existingTemplate = (ElemTemplate) m_namedTemplates.get(template.getName());
        if (null == existingTemplate)
        {
          m_namedTemplates.put(template.getName(), template);
        }
        else
        {
          int existingPrecedence =
                          existingTemplate.getStylesheetComposed().getImportCountComposed();
          int newPrecedence = template.getStylesheetComposed().getImportCountComposed();
          if (newPrecedence > existingPrecedence)
          {
            // This should never happen
            m_namedTemplates.put(template.getName(), template);
          }
          else if (newPrecedence == existingPrecedence)
            template.error(XSLTErrorResources.ER_DUPLICATE_NAMED_TEMPLATE,
                         new Object[]{ template.getName() });
        }
      }
  
      
  
      if (null != matchXPath)
      {
        Expression matchExpr = matchXPath.getExpression();
  
        if (matchExpr instanceof StepPattern)
        {
          insertPatternInTable((StepPattern) matchExpr, template);
        }
        else if (matchExpr instanceof UnionPattern)
        {
          UnionPattern upat = (UnionPattern) matchExpr;
          StepPattern[] pats = upat.getPatterns();
          int n = pats.length;
  
          for (int i = 0; i < n; i++)
          {
            insertPatternInTable(pats[i], template);
          }
        }
        else
        {
  
          // TODO: assert error
        }
      }
    }
docs: Add a template to the table of named templates and/or the table of templates
  with match patterns.  This routine should
  be called in decreasing order of precedence but it checks nonetheless.
  
  @param template