Copied to clipboard

Flag this post as spam?

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


  • Edward Aston 15 posts 35 karma points
    May 31, 2012 @ 13:17
    Edward Aston
    0

    Xslt html in an attribute - Help

    I'm trying to write a macro that will output the following:

    <a href="#"><img src="img/uploads/slide1.gif" rel="img/uploads/slide1.gif" alt="Slider image" title="<h2>Total Hub <em>your great service comes from our great service</em></h2>" /></a>


    I know it's a simple question but I'm really struggling to work out how to generate the title attributes test as it contains html tags.
    The text parts are sliderTitle and bodyText. So far I have:

        <xsl:for-each select="$currentPage/ancestor::root//homepageslider [@isDoc]">
            <xsl:variable name="imageId" select="sliderImage/text()" />
            <xsl:if test="$imageId != 0">         
              <xsl:variable name="image" select="umbraco.library:GetMedia($imageId,1)" />
                <a href="{umbraco.library:NiceUrl(@id)}">
                  <img src="{$image/umbracoFile}" rel="{$image/umbracoFile}" alt="{@nodeName}" title="" />             
              </a>
           </xsl:if>       
        </xsl:for-each>

    Thanks in advance,
    Ed
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    May 31, 2012 @ 13:30
    Chriztian Steinmeier
    0

    Hi Edward,

    You can not have real HTML in an attribute, but you can escape the tag-delimiters and have the receiving end unescape them if you need it - then you'd do something like this:

    <xsl:for-each select="$currentPage/ancestor::root//homepageslider[@isDoc]">
        <xsl:variable name="imageId" select="sliderImage" />
        <xsl:if test="normalize-space($imageId)">
            <xsl:variable name="image" select="umbraco.library:GetMedia($imageId, false())" />
            <a href="{umbraco.library:NiceUrl(@id)}">
                <img src="{$image/umbracoFile}" rel="{$image/umbracoFile}" alt="{@nodeName}" title="&lt;h2&gt;Total Hub &lt;em&gt;your great service comes from our great service&lt;/em&gt;&lt;/h2&gt;" />             
            </a>
        </xsl:if>
    </xsl:for-each>

    /Chriztian

  • Edward Aston 15 posts 35 karma points
    May 31, 2012 @ 13:47
    Edward Aston
    0

    Thanks Chirztian. I had tried this but not sure how to get it to output unescaped?

     

    Ignore my previous comment! I had an issue with my sliders js which was adding confussion to the issue. All sorted now thanks!

Please Sign in or register to post replies

Write your reply to:

Draft