You can use org-link-search
to find the subtree and org-element-parse-headline
to parse the subtree for headlines.
If you do that in a named Elisp source block you can use the output of that source block as input to another source block.
You can use the full heading text for the link search. But, I usually don't do that. I rather mark the heading by a target, e.g., <<mySubtree>>
and search for the target label mySubtree
.
There follows an example:
* Main Heading
** <<mySubtree>> Marked Subtree
*** Some subsection
*** Next subsection
* Other heading
#+NAME: mySubtreeSearch
#+BEGIN_SRC emacs-lisp
(let ((hl (save-excursion ;; syntax tree of the headline
(org-link-search "mySubtree")
(org-element-parse-headline 'headline))))
(cdr (org-element-map
hl
'headline
(lambda (el)
(org-element-property :title el)))))
#+END_SRC
#+RESULTS: mySubtreeSearch
| Some subsection | Next subsection |
#+BEGIN_SRC emacs-lisp :var tree=mySubtreeSearch
;; Here we just use the variable tree
tree
#+END_SRC
#+RESULTS:
| Some subsection | Next subsection |