How to create ATOM web feed

Hi Marius,

In my last reply, I mentioned have tried the your suggestion. In the code block, I pasted the abridged version

The exactly code block is as following.

{{velocity}}
## TODO: Rewrite this page completely so that it uses the same source as the Activity Stream Macro
## Backward compatibility redirect, if the ATOM feed is called without the outputSyntax query argument, force it.
#if (("$!request.xpage" == 'plain' || "$!request.xpage" == 'rdf') && "$!request.outputSyntax" != 'plain')
  $response.sendRedirect($xwiki.getURL($doc.fullName, 'view', 'xpage=plain&outputSyntax=plain'))
#end
#if ("$!request.xpage" == 'plain' && "$!request.outputSyntax" == 'plain')
  $response.setContentType('application/atom+xml')
  ## ======================
  ## Compute Query to find documents
  ## ======================
  #if("$!{request.tag}" != '')
    ## RSS feed for documents tagged with $request.tag
    #set ($query = 'from doc.object(XWiki.TagClass) as tag where (')
    #foreach ($tag in $request.getParameterValues('tag'))
      #set ($query = "$query :tag${foreach.count} member of tag.tags")
      #if ($foreach.hasNext)
        #set ($query = "$query OR ")
      #end
    #end
    #set ($query = "$query) AND ")
  #else
    #set ($query = 'where')
  #end
  #if("$!{request.space}" == '')
    ## RSS feed for the whole wiki
    #set ($query = "$query 1=1")
  #else
    ## RSS feed for spaces
    #set ($query = "$query (")
    #foreach ($space in $request.getParameterValues('space'))
      #set ($query = "$query doc.space=:space${foreach.count} OR doc.space LIKE :space_nested${foreach.count}")
      #if ($foreach.hasNext)
        #set ($query = "$query OR ")
      #end
    #end
    #set ($query = "$query)")
  #end
  #set ($query = "$query order by doc.date desc")
  ## ==============
  ## Bind Query parameters
  ## ==============
  ## Bind query parameters depending on the passed query string parameters
  #set ($queryObject = $services.query.xwql($query).addFilter('hidden/document').addFilter('currentlanguage').setLimit(20).setOffset(0))
  #if("$!{request.tag}" != '')
    #foreach ($tag in $request.getParameterValues('tag'))
      #set ($queryObject = $queryObject.bindValue("tag${foreach.count}", $tag))
    #end
  #end
  #if("$!{request.space}" != '')
    #foreach ($space in $request.getParameterValues('space'))
      #set ($queryObject = $queryObject.bindValue("space${foreach.count}", $space))
      #set ($queryObject = $queryObject.bindValue("space_nested${foreach.count}", "${space}.%"))
    #end
  #end
  ## ================
  ## Compute feed description
  ## ================
  ## 4 cases to handle: no spaces and tags specified, only spaces specified, only tags specified and spaces and tags specified
  #if ("$!{request.space}" != '')
    #if ("$!{request.tag}" != '')
      #set ($description = $services.localization.render('activity.rss.feed.tagsAndSpaces.description', [$stringtool.join($request.getParameterValues('tag'), ','), $stringtool.join($request.getParameterValues('space'), ',')]))
    #else
      #set ($description = $services.localization.render('activity.rss.feed.spaces.description', [$stringtool.join($request.getParameterValues('space'), ',')]))
    #end
  #else
    #if ("$!{request.tag}" != '')
      #set ($description = $services.localization.render('activity.rss.feed.tags.description', [$stringtool.join($request.getParameterValues('tag'), ',')]))
    #else
      #set ($description = $services.localization.render('activity.rss.feed.description'))
    #end
  #end
  ## =====================
  ## Execute query and generate feed
  ## =====================
  #set ($feed = $xwiki.feed.getWebFeed($queryObject.execute()))
  #foreach ($entry in $feed.entries)
    ## Clear the list of contributors. Ideally we should convert the String to a SyndPerson object but we can't do this from Velocity.
    #set ($discard = $entry.setContributors([]))
  #end
  #set ($feedURI = $xwiki.getDocument('Main.WebHome').getExternalURL('view'))
  #set ($discard = $feed.setLink($feedURI))
  #set ($discard = $feed.setUri($feedURI))
  #set ($discard = $feed.setAuthor('XWiki'))
  #set ($discard = $feed.setTitle($services.localization.render('activity.rss.feed.description')))
  #set ($discard = $feed.setDescription($description))
  #set ($discard = $feed.setLanguage("$xcontext.locale"))
  #set ($discard = $feed.setCopyright($xwiki.getXWikiPreference('copyright')))
  $xwiki.feed.getFeedOutput($feed, $xwiki.getXWikiPreference('feed_type', 'atom_1.0'))
#end
{{/velocity}}

The output is blank (0 byte), I wonder what is wrong with my code.

Update the complete code block according Marius suggested workaround solution.