You are right, Sparx EA doesn't pass the DiagramID and for Diagram/Element (which I presume is different form Package/Element) it doesn't not allow to put a Fragment inside the element enumeration.
However, there is a workaround. The Package ID is passed and your query can be extended to just include the elements referenced by the diagrams in the package. It is not exactly the way I wanted to do this but I does the job.
select
att.pos AS Pos
,obj.Name AS ObjectName
,att.Name AttributeName
,att.Notes AS Description_Formatted
,att.LowerBound
,att.UpperBound
,CASE WHEN x.Description is null THEN 'no' ELSE 'yes' END AS IsID
,COALESCE(v.Value, 'TBD') AS Versioned
,COALESCE(dc.VALUE,'TBD') as DataClassification
,COALESCE(ts.Value, 'TBD') AS Timesliced
,att.TYPE AS Format
from t_attribute att
left outer join t_attributetag v on (v.ElementID = att.ID
and v.Property = 'Versioned')
left outer join t_attributetag ts on (ts.ElementID = att.ID
and ts.Property = 'Timesliced')
left outer join t_attributetag dc on (dc.ElementID = att.ID
and dc.Property = 'Atrias::Data Classification')
left outer join t_xref x on (x.client = att.ea_guid
and x.Type = 'attribute property'
and x.Description like '%@PROP=@NAME=isID@ENDNAME;@TYPE=Boolean@ENDTYPE;@VALU=1@ENDVALU;%')
left outer join t_object obj
on obj.object_id = att.object_id
left outer join t_diagramobjects dobj
on att.object_id = dobj.object_id
left outer join t_diagram d
on dobj.diagram_id = d.diagram_id
where d.package_id = #PACKAGEID#
group by att.pos, obj.Name,att.Name, att.Notes, att.LowerBound, att.UpperBound, x.Description, v.Value, dc.VALUE, ts.Value, att.TYPE
union all
select 0, 'N/A', 'N/A', 'This class has no specific attributes' AS Description_Formatted, '', '',
'' AS IsID,
'' AS Versioned,'' as DataClassification, '' AS Timesliced, '' AS Format
where not exists
(select att2.ID from t_attribute att2
inner join public.t_diagramobjects dobj2
on att2.object_id = dobj2.object_id
inner join public.t_diagram d2
on dobj2.diagram_id = d2.diagram_id
where d2.package_id= #PACKAGEID#
)
order by ObjectName, Pos