Copied to clipboard

Flag this post as spam?

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


  • Anders Burla 2560 posts 8256 karma points
    Feb 10, 2012 @ 13:20
    Anders Burla
    0

    xslt attribute and danish html letters

    Hi

    I have a problem with my xslt. I have a rich text area where I have entered the danish letter å. This is translated into å

    Now i need this html value in my xlst. Here i need a xml element to have my html value as the attribute BUT it should be encoded as normal text again. So if I try and just use value-of and disable output escaping it doesnt work. It works if I just write that same value-of to the website, but as soon as I try and use it as an attribute for my xml element - the output is å

    Any knowledge how to fix that?

    Kind regards
    Anders

  • Jesper Ordrup 1019 posts 1528 karma points MVP
    Feb 10, 2012 @ 14:19
    Jesper Ordrup
    0

    Im probably missing the point?

    <xsl:variable name="mycontent">
    <xsl:value-of select="$currentPage/bodyText" disable-output-escaping="yes"/>
    </xsl:variable>
    <xsl:value-of select="$mycontent"/>

    Otherwise show some code pls?

    /Jesper

    ps. its friday

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 10, 2012 @ 14:22
    Chriztian Steinmeier
    0

    Hi Anders,

    It's very tricky because the å is plain text to the XSLT processor (it comes from a CDATA Section) and because of the rules for escaping it simply won't write a solitary ampersand character to an attribute...

    The "right" way to do it would be to use the Parse() method in uComponents to convert it to XML, 'coz then you'd just do a value-of as usual - but you may need to do some very tricky entity stuff in combination with that...

    Will look into it - I know Lee Kelleher made some improvements to the Parse() method which may be able to do the conversion for you.

    @Jesper: The thing is that it should go inside of an attribute - and if you try that, the parser will force an ecaped ampersand, no matter what you try.

    /Chriztian

  • Anders Burla 2560 posts 8256 karma points
    Feb 10, 2012 @ 15:17
    Anders Burla
    0

    Hi Chriztian

    I right - exactly my problem - you would be my hero this week if you find a method to solve it - crossing my fingers :)

    Kind regards
    Anders

  • Berto 105 posts 177 karma points
    Feb 10, 2012 @ 15:55
    Berto
    0

    I just wrote this, and didn't had the time and an umbraco instalation to test it, but i think this might work:

     

     

     <xsl:variable name="yourXmlVar" >  
        <xsl:for-each select="$currentPage/node">
    <xsl:text disable-output-escaping="yes"><theXmlNode MyAtt="</xsl:text><xsl:value-of disable-output-escaping="yes" select="text"/><xsl:text disable-output-escaping="yes">">Now another text</theXmlNode></xsl:text>
    </xsl:for-each>
      </xsl:variable>  
      <xsl:variable name="xmlWithTheChars" select="msxml:node-set($yourXmlVar)" /> 

    What i do is to create the string to a variable, and then transform it to xml... 

    I hope it helps

     

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 10, 2012 @ 19:33
    Chriztian Steinmeier
    0

     

    @Berto,

    You *can* create the entire tag using that technique, i.e.:

    <xsl:text disable-output-escaping="yes"><![CDATA[<body title="]]></xsl:text>
    <xsl:value-of select="propertyWithDanishCharacters" disable-output-escaping="yes" />
    <xsl:text disable-output-escaping="yes"><![CDATA[">]]></xsl:text>
        <!-- contents of faked body element... -->
    <xsl:text disable-output-escaping="yes"><![CDATA[</body>]]></xsl:text>
    

    But it very quickly becomes unmanageable because you have to also render the closing tag using this technique - otherwise you'll get wellformedness errors. It's the very last resort, but indeed may be the only option if it's not possible to do "the right way" ... 

    Guess it depends on how much is going to be rendered this way.

    @Anders: Are the characters coming from TinyMCE ? I've never had this problem - I'd actually guess it's a paste from Word or similiar editor? Otherwise, maybe TinyMCE has a setting for this? With UTF-8 it shouldn't do this conversion anyway ... 

    /Chriztian

     

  • Anders Burla 2560 posts 8256 karma points
    Feb 17, 2012 @ 12:22
    Anders Burla
    0

    Hi Christian

    No the text is a tinyMCE field at the website where people can make forum posts and comments. People might copy from Word - we dont know if they do and can't do anything about it if they do :) This text is saved in a custom DB table.

    Do you have an idea of what we should do?

    Kind regards
    Anders

  • Berto 105 posts 177 karma points
    Feb 17, 2012 @ 13:15
    Berto
    1

    Anders, 

    The text is not on umbraco? How do you get text from your db? If you are using a costum method, when you get the the value from the db, you can do a Server.HtmlDecode of the string, or HttpUtility.HtmlDecode.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 17, 2012 @ 23:18
    Chriztian Steinmeier
    0

    Hi Anders,

    I'll second Bertos suggestion - since you're already doing something a little customary, I'd say the obvious place to perform the "sanitation" is either (preferrably) when you save the data, or when you read them.

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft