code: private List getRetainedPagesWithTemplate(List xmlPages) {
  
          // list of resources belongs to the selected template
          List resourcesWithTemplate = new ArrayList();
          TreeMap templates = null;
          try {
              templates = CmsNewResourceXmlPage.getTemplates(getCms(), null);
          } catch (CmsException e) {
              if (LOG.isErrorEnabled()) {
                  LOG.error(e.getLocalizedMessage(), e);
              }
          }
          // check if the users selected template is valid.
          if ((templates != null) && templates.containsValue(getParamTemplate())) {
              // iterate the xmlPages list and add all resources with the specified template to the resourcesWithTemplate list
              Iterator i = xmlPages.iterator();
              while (i.hasNext()) {
                  CmsResource currentPage = (CmsResource)i.next();
                  // read the template property
                  CmsProperty templateProperty;
                  try {
                      templateProperty = getCms().readPropertyObject(
                          getCms().getSitePath(currentPage),
                          CmsPropertyDefinition.PROPERTY_TEMPLATE,
                          false);
                  } catch (CmsException e2) {
                      if (LOG.isErrorEnabled()) {
                          LOG.error(e2);
                      }
                      continue;
                  }
                  // add currentResource if the template property value is the same as the given template
                  if (getParamTemplate().equals(templateProperty.getValue())) {
                      resourcesWithTemplate.add(currentPage);
                  }
              }
              // retain the list of pages against the list with template
              xmlPages.retainAll(resourcesWithTemplate);
          }
  
          return xmlPages;
      }
docs: Returns a retained list of xml pages that belongs to the specified template.<p>
  
  @param xmlPages a list of all xml pages
  @return a retained list of xml pages that belongs to the specified template