开发者

How can I put an html text in a label with xsl?

Assume I have an xml document I have a tag containing html text. I want to display this text with the xsl. The html tag is htmlInfo.

I tought I can put this开发者_运维知识库 in a label (in the xsl), but it doesn't work. What can I do?


You will probably have to encode it into your XML, so it looks like this:

<tableInfo> 
    <id>1</id> 
    <htmlInfo>
        &lt;html xmlns='w3.org/1999/xhtml'&gt;&lt;head &gt;&lt;/head&gt; &lt;body&gt;&lt;p&gt;xzxzxzxzxz&lt;/p&gt; &lt;p&gt;hghghgh&lt;/p&gt; &lt;/body&gt;&lt;/html&gt;
    </htmlInfo>
<tableInfo>

So all < characters have been replaced with &lt; and all > characters have been replaced with &gt;. An & should be &amp; ... 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 &lt; and other stuff should correctly be '<' in the output, and your HTML should be valid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜