in the xml i have a tag with html text, i want do display this html with the xsl. the html tag is htmlInfo. i tought i can put this in a label(in the xsl), but it doesnt work. what can i do?
A:
You will probably have to encode it into your XML, so it looks like this:
<tableInfo>
<id>1</id>
<htmlInfo>
<html xmlns='w3.org/1999/xhtml'><head ></head> <body><p>xzxzxzxzxz</p> <p>hghghgh</p> </body></html>
</htmlInfo>
<tableInfo>
So all < characters have been replaced with < and all > characters have been replaced with >. An & should be & ... If you're using .NET, don't use String.Replace, but use the System.Xml namespace to correctly build an XmlDocument. It will do the encoding for you. For example, in VB.Net:
Dim stringBuilder As New StringBuilder()
Dim stringWriter As New StringWriter(stringBuilder)
Dim xmlTextWriter As New XmlTextWriter(stringWriter)
xmlTextWriter.WriteStartElement("item")
xmlTextWriter.WriteAttributeString("id", id.ToString())
xmlTextWriter.WriteAttributeString("key", key)
xmlTextWriter.WriteValue(value)
xmlTextWriter.WriteEndElement()
Return stringBuilder.ToString()
Then, your XSL should be able to handle it, and if you output the transform to a HTML file for example, the '<' and other stuff should correctly be '<' in the output, and your HTML should be valid.
Peter
2010-06-15 09:26:01
i used xmlDocument. but how can i encode the html to xml. and when?
joe
2010-06-15 09:36:41
Which method on XmlDocument are you using to write the htmlInfo tag?
Peter
2010-06-15 11:00:52
xsl.Load(xslUrl); // Transform the xml XPathNavigator navigator = xmlDs.DocumentElement.CreateNavigator(); StringBuilder sbTransHtml = new StringBuilder(); StringWriter strwTransHtml = new StringWriter(sbTransHtml); XmlTextWriter xmltwTransHtml = new XmlTextWriter(strwTransHtml); xsl.Transform(navigator, null, xmltwTransHtml); return strwTransHtml.ToString();
joe
2010-06-15 11:08:09
Sorry, I can't seem to get it to work either. If I do, I'll let you know, but if someone else knows, I'd love to hear it.
Peter
2010-06-15 13:05:00