def METHOD_NAME(page_name, site_mode, version=None):
    """
    look for the xml file with this name. if found,
    look inside the xml file for a stylesheet processing
    instruction, apply the transformation and return the
    transformed document.
    """
    # Simple security check to prevent walking the filesystem
    if page_name.find("../") != -1:
        raise Error404
    match = re.match('/(.*?)(\\.html)?$', page_name)
    if match:
        page_name = match.group(1)
        page_id = match.group(1)
    else:
        raise Error404
    if page_name == '':
        page_name = 'index'
    xml_doc = read_file(page_name)
    xml_doc.xinclude()
    query = '/processing-instruction(\'xml-stylesheet\')'
    xslt_file_name = xml_doc.xpath(query)[0].get('href')
    xslt_doc = parse(os.path.join(SITE_DIR, xslt_file_name))
    params = {'page-name': "'/%s.html'" % page_name,
              'site-mode': "'%s'" % site_mode,
              'page-id': "'%s'" % page_id}
    transform = etree.XSLT(xslt_doc)
    xhtml_doc = transform(xml_doc, **params)
    if version:
        xslt_rebase = parse(os.path.join(SITE_DIR, 'rebase.xsl'))
        param = {'link-prefix': "'%s'" % version}
        transform = etree.XSLT(xslt_rebase)
        result = transform(xhtml_doc, **param)
    else:
        result = xhtml_doc
    return str(result)