content: -- List tags in the document
  -- Filter by selected tags
  property pTitle : "Filter by tag"
  property pVer : "0.04"
  
  -- LIST TAGS IN DOCUMENT, 
  -- AND SELECT TAGS TO TO FILTER
  
  
  property pblnSort : true -- sorted list of tags ?
  
  tell application "FoldingText"
  	set lstDocs to documents
  	if lstDocs ≠ {} then
  		tell item 1 of lstDocs
  			-- LIST THE TAGS IN THE FRONT DOCUMENT,
  			set lstTags to my allTags(it, pblnSort)
  			tell application id "sevs"
  				activate
  				set varChoice to choose from list lstTags with title pTitle & tab & pVer with prompt ¬
  					"(Cancel to unfilter)" & linefeed & linefeed & "Choose:" default items {} ¬
  					OK button name "OK" cancel button name "Cancel" with empty selection allowed and multiple selections allowed
  			end tell
  			
  			-- AND FILTER THE DOCUMENT BY ANY USER-CHOSEN TAG(S)
  			if varChoice = false then
  				update node path it with text "///*"
  				return missing value
  			end if
  			set strPath to ""
  			repeat with i from 1 to length of varChoice
  				if i > 1 then set strPath to strPath & " UNION "
  				set strPath to strPath & "//@" & item i of varChoice
  			end repeat
  			update node path it with text strPath
  			activate
  		end tell
  	end if
  end tell
  
  on allTags(oDoc, blnSorted)
  	set lstAllTags to {}
  	tell application "FoldingText"
  		tell oDoc
  			repeat with oNode in (read nodes it at path "//@line:tag") as list
  				repeat with oTag in (contents of (tagNames of oNode))
  					if lstAllTags does not contain oTag then set end of lstAllTags to contents of oTag
  				end repeat
  			end repeat
  		end tell
  	end tell
  	if blnSorted then
  		if lstAllTags ≠ {} then
  			set {dlm, my text item delimiters} to {my text item delimiters, linefeed}
  			set lstAllTags to paragraphs of (do shell script "echo " & quoted form of (lstAllTags as string) & " | sort")
  			set my text item delimiters to dlm
  		end if
  	end if
  	return lstAllTags
  end allTags
  