def self.find_node_from_text(doc, text, next_link=false, index = 0)
text.gsub!('ยป', '»')
if text =~ /.+\/@.+$/
text = text.scan(/^(.+?)\/@.+$/)[0][0]
elsif text =~ /.+\[\d+\]$/
res = text.scan(/(.+)\[(\d+)\]$/)
text = res[0][0]
index = res[0][1].to_i
elsif text =~ /.+\[.+\]$/
final_element_name = text.scan(/^(.+?)\[/)[0][0]
text = text.scan(/\[(.+?)\]/)[0][0]
end
if final_element_name
text = Regexp.escape(text) if text.is_a? String
result = SharedUtils.traverse_for_match(doc,/#{text}/)[index]
result = XPathUtils.traverse_up_until_name(result,final_element_name)
else
text = Regexp.escape(text) if text.is_a? String
result = SharedUtils.traverse_for_match(doc,/^#{text}$/)[index]
end
end