Copied to clipboard

Flag this post as spam?

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


  • manuelpedrera 18 posts 38 karma points
    Nov 23, 2010 @ 21:25
    manuelpedrera
    0

    HTML Entities in XSLT

    Hi, I am getting some node properties which have an "&" character, and the XSLT is converting them to HTML entities by default. Is there any way I can avoid this behaviour?


    A fragment from the code:

    <video>
          <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
          <xsl:value-of select="video"/>
          <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
    </video>
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Nov 23, 2010 @ 21:36
    Chriztian Steinmeier
    0

    Hi manuelpedrera,

    To have the processor output video elements as CDATA, you need to set an attribute on the <xsl:output /> element:

    <xsl:output cdata-section-elements="video" />
    ...
    <video>
        <xsl:value-of select="video" disable-output-escaping="yes" />
    </video>

    This is how you create a CDATA Section in XML output... depending on what's in the video element in the first place, you might go for another solution, which is to just copy the video element from the source to the output:

    <xsl:copy-of select="video" />

    Which will copy the entire <video> element (so don't put <video> tags around it).

    /Chriztian

  • manuelpedrera 18 posts 38 karma points
    Nov 23, 2010 @ 21:43
    manuelpedrera
    0

    Hi Christian, thank you very much for your reply.

     

    However, what I'm asking for is a way to avoid this situation. What I'm getting now is:

    <thumbnail><![CDATA[/media/1959/j&amp;b phoenician gotas silueta.jpg]]></thumbnail>

    And what I want is (changing the "&amp;" for an "&"):

    <thumbnail><![CDATA[/media/1959/j&b phoenician gotas silueta.jpg]]></thumbnail>

    Why? Because the front-end is a flash movie and it's trying to load the videos & images with html entities, which obviously doesn't work.


    By the way, thanks for that CDATA trick ;)

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Nov 23, 2010 @ 22:08
    Chriztian Steinmeier
    0

    Hi again,

    I thought so :-)

    But that's really another problem - ampersands in URLs (and thus, file references) must be URLEncoded - so that URL will never work, unless encoded like this:

    /media/1959/j%26b phoenician gotas silueta.jpg (and even the spaces ought to be output as %20 too)

    So you should really look at the umbraco.library:URLEncode() extension method for this (that is if you can't persuade the editors not to use ampersands in filenames :-)

    /Chriztian

  • manuelpedrera 18 posts 38 karma points
    Nov 24, 2010 @ 11:54
    manuelpedrera
    0

    Thank you Chriztian ;)

    I added the

    disable-output-escaping="yes"

    to the xsl:value-of sentence and it worked too.

Please Sign in or register to post replies

Write your reply to:

Draft