'XML Element tree export method
@param r: the S3Request instance
@param attr: controller attributes'

@staticmethod
def get_tree(r, **attr):

    get_vars = r.get_vars
    args = Storage()
    start = get_vars.get('start')
    if (start is not None):
        try:
            start = int(start)
        except ValueError:
            start = None
    limit = get_vars.get('limit')
    if (limit is not None):
        try:
            limit = int(limit)
        except ValueError:
            limit = None
    msince = get_vars.get('msince')
    if (msince is not None):
        msince = s3_parse_datetime(msince)
    if ('show_ids' in get_vars):
        if (get_vars['show_ids'].lower() == 'true'):
            current.xml.show_ids = True
    if ('show_urls' in get_vars):
        if (get_vars['show_urls'].lower() == 'false'):
            current.xml.show_urls = False
    maxbounds = False
    if ('maxbounds' in get_vars):
        if (get_vars['maxbounds'].lower() == 'true'):
            maxbounds = True
    if (r.representation in ('gpx', 'osm')):
        maxbounds = True
    if ('mcomponents' in get_vars):
        mcomponents = get_vars['mcomponents']
        if (str(mcomponents).lower() == 'none'):
            mcomponents = None
        elif (not isinstance(mcomponents, list)):
            mcomponents = mcomponents.split(',')
    else:
        mcomponents = []
    if ('rcomponents' in get_vars):
        rcomponents = get_vars['rcomponents']
        if (str(rcomponents).lower() == 'none'):
            rcomponents = None
        elif (not isinstance(rcomponents, list)):
            rcomponents = rcomponents.split(',')
    else:
        rcomponents = None
    if ('maxdepth' in get_vars):
        try:
            args['maxdepth'] = int(get_vars['maxdepth'])
        except ValueError:
            pass
    if ('references' in get_vars):
        references = get_vars['references']
        if (str(references).lower() == 'none'):
            references = []
        elif (not isinstance(references, list)):
            references = references.split(',')
    else:
        references = None
    if ('fields' in get_vars):
        fields = get_vars['fields']
        if (str(fields).lower() == 'none'):
            fields = []
        elif (not isinstance(fields, list)):
            fields = fields.split(',')
    else:
        fields = None
    stylesheet = r.stylesheet()
    if (stylesheet is not None):
        if r.component:
            args['id'] = r.id
            args['component'] = r.component.tablename
            if r.component.alias:
                args['alias'] = r.component.alias
        mode = get_vars.get('xsltmode')
        if (mode is not None):
            args['mode'] = mode
    response = current.response
    s3 = response.s3
    headers = response.headers
    representation = r.representation
    if (representation in s3.json_formats):
        as_json = True
        default = 'application/json'
    else:
        as_json = False
        default = 'text/xml'
    headers['Content-Type'] = s3.content_type.get(representation, default)
    resource = r.resource
    target = r.target()[3]
    if (target == resource.tablename):
        target = None
    output = resource.export_xml(start=start, limit=limit, msince=msince, fields=fields, dereference=True, references=references, mcomponents=mcomponents, rcomponents=rcomponents, stylesheet=stylesheet, as_json=as_json, maxbounds=maxbounds, target=target, **args)
    if (not output):
        r.error(400, ('XSLT    Transformation    Error:    %s    ' % current.xml.error))
    return output
