Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • René Andersen 238 posts 684 karma points
    Dec 07, 2011 @ 12:42
    René Andersen
    0

    Fetching Anchor Points from Richtext Editor

    Is there a way to fetch anchor points from the richtext editor via XSLT or Razor, so that it shows the anchor links (example on the right side of the page) when they are defined in the richtext editor. I need it to be dynamic, because that i dont have anchor points on every page, so that the (right side) is blank when the anchor points aren't defined.

    It is pretty hard to explain in english, so i hope that you understand my question.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 07, 2011 @ 14:24
    Tom Fulton
    1

    Hi Rene,

    You can do this using uComponents' xml:Parse XSLT extension if you have uComponents installed.  Chriztian has posted a nice include file for parsing WYSIWYG content here.  Following his example, here's a simple XSLT to find the anchor tags (a tags with no href or with no content) within the bodyText:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
      <!ENTITY nbsp "&#x00A0;">
      <!ENTITY embedded-doctype "&lt;!DOCTYPE WYSIWYG [ &lt;!ENTITY nbsp &quot;&amp;#160;&quot;&gt; ]&gt;">
      <!ENTITY EditorContent "concat('&embedded-doctype;&lt;&wrapper;&gt;', ., '&lt;/&wrapper;&gt;')">
      <!ENTITY wrapper "WYSIWYG">
    ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:ucomponents.xml="urn:ucomponents.xml"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ucomponents.xml ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

        <xsl:template match="/">
          <xsl:apply-templates select="$currentPage/bodyText" mode="WYSIWYG"/>
        </xsl:template>
       
        <xsl:template match="*" mode="WYSIWYG">
          <xsl:apply-templates select="ucomponents.xml:Parse(&EditorContent;)//a [not(@href) or not(normalize-space(.))]"/>
        </xsl:template>

        <xsl:template match="a">
          <a href="#{@id}">
            <xsl:value-of select="@name"/>
          </a>
          <br/>
        </xsl:template>
    </xsl:stylesheet>

    Note you need to have the ucomponents.xml extension enabled in your /config/xsltExtensions.config:

    <ext assembly="uComponents.Core" type="uComponents.Core.XsltExtensions.Xml" alias="ucomponents.xml" />

    Hope this helps,
    Tom

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 07, 2011 @ 23:28
    Chriztian Steinmeier
    0

    @Tom: Kudos for writing that answer!

    I was going to suggest using my include, but thought it was just a tad on the advanced side of things, but you just pulled the necessary bits. Great!

    Note: Lee has since fixed some things to make this easier, so there'll be a couple of new Parse*** methods in uComponents that will take care of the stuff I'm "entitizing" my way out of...

    /Chriztian 

Please Sign in or register to post replies

Write your reply to:

Draft