'Bit' late, but thought your questions was interesting.
So given the attached file which resembles your FAQ docs based on what you wrote, here is the code to sort the headings accordingly. Code could be cleaner but its late and I couldn't be bothered :)
Code runs fine on v6 and v7 of LO that I tested. The attached document includes the macro.
[Sub sortHeadings()
Dim oDoc: oDoc = ThisComponent
Dim allSorted: allSorted = false
do
Dim SDescript
SDescript = oDoc.createSearchDescriptor
SDescript.setPropertyValue("SearchStyles", True)
SDescript.setSearchString("Heading 1")
Dim FoundRanges
FoundRanges = oDoc.findAll(SDescript)
Dim Count
Count = FoundRanges.Count
'Print Count
Dim i As integer
For i=0 To (Count -2)
Dim aRange, aText
aRange = FoundRanges.getByIndex(i)
aText = aRange.getString()
Dim bRange, bText
bRange = FoundRanges.getByIndex(i+1)
bText = bRange.getString()
If UCASE(bText) < ucase(aText) Then
Dim aTC, bTC
aTC = oDoc.Text.createTextCursorByRange(aRange)
aTC.gotoRange(bRange.start(),true)
bTC = oDoc.Text.createTextCursorByRange(bRange)
If i+2 = Count Then 'at last two blocks?
Dim dText
dText = oDoc.getText()
bTC.gotoRange(dText.end(),true)
'msgbox "B-Block: " & bTC.getString()
Else
Dim nRange
nRange = FoundRanges.getByIndex(i+2)
bTC.gotoRange(nRange.start(),true)
'msgbox "B-Block: " & bTC.getString()
End If
'
' Swap text blocks
'
' Grab a copy
Dim oCC: oCC = ThisComponent.CurrentController
oCC.Select(bTC)
Dim o: o = oCC.getTransferable()
' Remove copied text
bTC.setString("")
' Move Cursor and Insert text
Dim oVC: oVC = oCC.getViewCursor()
oVC.gotoRange(aRange.getStart(),false)
oCC.insertTransferable(o)
'restart loop to account for block moving...
Exit For
Else
' Last two didnt need to be swapped we are done.
If i+2 = Count Then
allSorted = true
End if
End If
Next
Loop While Not allSorted
Print "Sorting completed!!"
End Sub]
C:\fakepath\sortTextWithHeadings.odt