[Solved] Figure Text in same Document with Anchor Tag

Balaji Asks: Figure Text in same Document with Anchor Tag
I had referred this link: Create Separate File using LuaLaTeX

But i have need in the same document.

I would like to give anchor tags in the figure caption and move the figure caption text in the top of the document.

My MWE is:

Code:
documentclass{article}
usepackage{luacode}


begin{document}

begin{luacode*}
local domobject = require "luaxml-domobject"
sample = [[
<?xml version="1.0" encoding="utf-8"?>
<art>
<title>Scattering of flexural waves an electric current</title>
<para>Smart testing structures are components <figure id="ab8cf1" position="float"><label>Figure 1.</label><caption id="ab8cf1"><p>Carter–Penrose diagram for the inverted black hole spacetime. The lines <italic>x</italic> = 0 are repulsive singularities, the intersecting lines <italic>x</italic> = 1 form a Killing horizon, and <italic>x</italic> = ∞ is a temporal infinity.</p></caption><graphic id="ab8cf1" content-type="print" xlink:href="ab8cf1.pdf"/><graphic id="ab8cf1" content-type="high" xlink:href="ab8cf1.jpg"/></figure> used in engineering applications that are capable of sensing or reacting to their environment <figure id="ab8cf2" position="float"><label>Figure 2.</label><caption id="ab8cf2"><p>Carter–Penrose diagram for the inverted black hole spacetime. The lines <italic>x</italic> = 0 are repulsive singularities, the intersecting lines <italic>x</italic> = 1 form a Killing horizon, and <italic>x</italic> = ∞ is a temporal infinity.</p></caption><graphic id="ab8cf2" content-type="print" xlink:href="ab8cf2.pdf"/><graphic id="ab8cf2" content-type="high" xlink:href="ab8cf2.jpg"/></figure> in a predictable and desired manner. In addition to carrying mechanical loads, <!--may smart structures--> alleviate vibration, reduce acoustic noise, change their mechanical properties as required or monitor their own condition.</para>
</art>
]]

local dom = domobject.parse(sample)
dom:traverse_elements(function(el)
--local FigNo = el:get_element_name():match("%<fig id="(.-)"")
--local FigCount = el:get_element_name():match("%<fig id="(.-)f([0-9]+)"")
print("FigNo IS:",FigNo)
--dom=string.gsub(dom,"<fig id(.-)</fig>,"\InsertFigure{FigNo}{f..FigCount}{}{b}")
end)
end{luacode*}
end{document}

I would like the result is:

Code:
    begin{luacode*}
    local domobject = require "luaxml-domobject"
    sample = [[
    <?xml version="1.0" encoding="utf-8"?>
    <art>
<figure id="ab8cf1" position="float"><label>Figure 1.</label><caption id="ab8cf1"><p>Carter–Penrose diagram for the inverted black hole spacetime. The lines <italic>x</italic> = 0 are repulsive singularities, the intersecting lines <italic>x</italic> = 1 form a Killing horizon, and <italic>x</italic> = ∞ is a temporal infinity.</p></caption><graphic id="ab8cf1" content-type="print" xlink:href="ab8cf1.pdf"/><graphic id="ab8cf1" content-type="high" xlink:href="ab8cf1.jpg"/></figure>
<figure id="ab8cf2" position="float"><label>Figure 2.</label><caption id="ab8cf2"><p>Carter–Penrose diagram for the inverted black hole spacetime. The lines <italic>x</italic> = 0 are repulsive singularities, the intersecting lines <italic>x</italic> = 1 form a Killing horizon, and <italic>x</italic> = ∞ is a temporal infinity.</p></caption><graphic id="ab8cf2" content-type="print" xlink:href="ab8cf2.pdf"/><graphic id="ab8cf2" content-type="high" xlink:href="ab8cf2.jpg"/></figure>
    <title>Scattering of flexural waves an electric current</title>
    <para>Smart testing structures are components \InsertFigure{ab8cf1}{f1}{}{t} used in engineering applications that are capable of sensing or reacting to their environment \InsertFigure{ab8cf2}{f2}{}{t} in a predictable and desired manner. In addition to carrying mechanical loads, <!--may smart structures--> alleviate vibration, reduce acoustic noise, change their mechanical properties as required or monitor their own condition.</para>
    </art>
    ]]

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.