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 å
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.
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 ...
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.
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.
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.
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 &aring;
Any knowledge how to fix that?
Kind regards
Anders
Im probably missing the point?
Otherwise show some code pls?
/Jesper
ps. its friday
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
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
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
@Berto,
You *can* create the entire tag using that technique, i.e.:
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
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
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.
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
is working on a reply...