No need for macro. if you are using transformation, which is ascx control, you use pure c#: should be something like:
<script runat="server">
string docName = "";
protected override void OnInit(EventArgs e)
{
var docURL = CMS.Helpers.ValidationHelper.GetString(Eval("URLselectorFieldName"), "");
// you get something like ~/News/Apple-iPad-2-In-Stock.aspx - you need strip some parts
// in order to get '/News/Apple-iPad-2-In-Stock'
docURL = docURL.Replace("~","").Replace(".aspx","")
if (docURL != "")
{
docName = CMS.DocumentEngine.DocumentHelper.GetDocuments("your doc type")
.WhereEquals("NodeAliasPath", docURL)
.FirstOrDefault()?.GetValue("DocumentName");
}
}
</script>
<%=docName%><br>
It is not tested - it just to give you the direction.
Don't forget about performance probably your transformation will be called many times and each time it will produce a call to resolve a document name. I dont really know you set up, and how the url are defined.
You can go with macro but DocumentHelper can let do more efficient query than {% Documents %} macro.