I wanna show the list of Pages using the tags in Macro, But only the Published Pages

I have tried the key “isPublished()” method, but its not working, not showing any page links,
but if i removed the isPublished condition it shows, Draft Version & Target Version.

Anyone Could help on this issue ?

{{html clean=“false”}}
#set ($list = $xwiki.tag.getDocumentsWithTag('TagName))
#set ($tableHtml = "")
#set ($counter = 1)
#foreach($reference in $list)
#set ($document = $xwiki.getDocument($reference))
#if ($document.isPublished())
#set ($label = $document.getTitle())
#set ($tableHtml = $tableHtml + "")
#set ($counter = $counter + 1)
#end
#end
#set ($tableHtml = $tableHtml + “

S.no Link Description
$counter $label
”) $tableHtml {{/html}}