Reporting dead links in Multiple content picker

The Umbraco multi content picker is a wonderful little control, but can sometimes become a bit of a maintenance nightmare. The example below gives you an idea of how to implement dead link notification within XSLT.

The other way to deal with this would be have an action handler checking document integrity each time a publish occured, but this is a nice quick fix if you have a relatively small amount of content.

<xsl:if test="count($currentPage/data[@alias = 'Links']/nodes/node) > 0">
  <ul class="courselinks">
    <xsl:for-each select="$currentPage/data[@alias = 'Links']/nodes/node">
      <xsl:variable name="child" select="umbraco.library:GetXmlNodeById(./text())" />
      <xsl:choose>
        <xsl:when test="$child/@id != ''">
          <li>
            <a href="{umbraco.library:NiceUrl($child/@id)}">
              <xsl:value-of select="$child/data[@alias='Page Title']"/>
            </a>
          </li>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="reportDeadLink">
            <xsl:with-param name="linkId" select="./text()"/>
            <xsl:with-param name="pageId" select="$currentPage/@id"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
  </ul>
</xsl:if>

<xsl:template name="reportDeadLink">
  <xsl:param name="linkId"/>
  <xsl:param name="pageId"/>

  <xsl:value-of select="
            umbraco.library:SendMail(   
                umbraco.library:GetDictionaryItem('frommail'), 
                umbraco.library:GetDictionaryItem('brokenlinkmail'), 
                'Broken Link', 
                concat('Broken link to node ', $linkId, ' in ', umbraco.library:NiceUrl($pageId)), 
                0)"/>
</xsl:template>

I store my email addresses as Umbraco dictionary items, but you could always hard code them in your XSLT.

Leave a comment