Get multiple xdom blocks in order

I have a page that has both paragraph and quotation block contents that are mixed. I am able to get both with the following snippet of code:

  #foreach ($block in $document.getXDOM().getBlocks('class:ParagraphBlock', 'DESCENDANT'))
    #set ($xwikiSyntax = $services.rendering.render($block, "xwiki/2.1"))
    $xwikiSyntax
  #end

  #foreach ($block in $document.getXDOM().getBlocks('class:QuotationBlock', 'DESCENDANT'))
    #set ($xwikiSyntax = $services.rendering.render($block, "xwiki/2.1"))
    $xwikiSyntax
  #end

The one problem here though is that the content is not rendered in order (i.e. all the paragraph content is rendered and then the quoted content; I’d like them to be printed out in their original order)

How would I do this?

Thanks.

You’d need to use a single getBlocks() call with a BlockMatcher matching the 2 block types you’re looking for. For example with a OrBlockMatcher.

Example: xwiki-rendering/xwiki-rendering-api/src/test/java/org/xwiki/rendering/block/match/OrBlockMatcherTest.java at 7cac6e9dc68d6334deaf947cc15d8cde4dd7ee4b · xwiki/xwiki-rendering · GitHub

You’ll need to use a Groovy script since I don’t think you can do that with a velocity script.