如何把xml中CDATA节中的空白和换行符还原?20分,分虽然少,请帮帮偶

时间:2021-04-13 20:41:27
如何把xml中CDATA节中的空白和换行符还原?

我现在有一个XML文件(通过XmlTextWriter得到)

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<?xml-stylesheet type='text/xsl' href='main.xsl'?>
<!--此站点由Myway_Lau开发 | This Site is Created by Myway_Lau | Email:Myway_Lau@hotmail.com-->
<Myway_Lau的站点>
  <文章>
    <标题><![CDATA[在IIS中运行]]></标题>
    <内容><![CDATA[很多很多哦


啦啦啦]]></内容>
    <分类><![CDATA[网络编程]]></分类>
    <来自><![CDATA[来自]]></来自>
    <相关链接><![CDATA[http://www.xxxx.org]]>;</相关链接>
    <图片><![CDATA[ty.bmp]]></图片>
    <图片对齐><![CDATA[right]]></图片对齐>
    <录入时间><![CDATA[2004-8-13-23-05-33]]></录入时间>
    <评论地址><![CDATA[2004-8-13-23-05-33.xml]]></评论地址>
  </文章>
</Myway_Lau的站点>






偶的<内容>CDATA中间有很多的空格和换行,不过经过xsl转换之后,中间那些就变成了一个空格了……





请问应该如何解决……   :)

XSL如下:



<?xml version="1.0" encoding="utf-8"?>
<html xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:for-each select="Myway_Lau的站点/文章">
<head>
<link href="styles.css" rel="stylesheet" type="text/css"/>
<script language="javascript">
function mhEnter()
{
window.event.srcElement.className="lt1";
}
function mhLeave()
{
window.event.srcElement.className="lt0";
}
</script>
<body background="images/bg1.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" align="center">
<table width="776" align='center' border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<img src="images/logo.jpg" width="776" height="180"/><br/>
<tr><td class="lt0" nowrap="true" onmouseenter="mhEnter()" onmouseleave="mhLeave()"><a href="index.aspx"><b>站点首页</b></a></td><td class='ltsep'>|</td><td class="lt0" nowrap="true" onmouseenter="mhEnter()" onmouseleave="mhLeave()"><a href="category.aspx?cat=RIA开发"><b>RIA开发</b></a></td><td class='ltsep'>|</td><td class="lt0" nowrap="true" onmouseenter="mhEnter()" onmouseleave="mhLeave()"><a href="category.aspx?cat=网络编程"><b>网络编程</b></a></td><td class='ltsep'>|</td><td class="lt0" nowrap="true" onmouseenter="mhEnter()" onmouseleave="mhLeave()"><a href="category.aspx?cat=Flash AS"><b>Flash AS</b></a></td><td class='ltsep'>|</td><td class="lt0" nowrap="true" onmouseenter="mhEnter()" onmouseleave="mhLeave()"><a href="category.aspx?cat=视觉冲击"><b>视觉冲击</b></a></td><td class='ltsep'>|</td><td class="lt0" nowrap="true" onmouseenter="mhEnter()" onmouseleave="mhLeave()"><a href="category.aspx?cat=作品展示"><b>作品展示</b></a></td><td class='ltsep'>|</td><td class="lt0" nowrap="true" onmouseenter="mhEnter()" onmouseleave="mhLeave()"><a href="category.aspx?cat=资源教程"><b>资源教程</b></a></td><td class='ltsep'>|</td><td class="lt0" nowrap="true" onmouseenter="mhEnter()" onmouseleave="mhLeave()"><a href="category.aspx?cat=发烧音频"><b>发烧音频</b></a></td><td class='ltsep'>|</td><td class="lt0" nowrap="true" onmouseenter="mhEnter()" onmouseleave="mhLeave()"><a href="category.aspx?cat=闲言碎语"><b>闲言碎语</b></a></td><td class='ltsep'>|</td><td class="lt0" nowrap="true" onmouseenter="mhEnter()" onmouseleave="mhLeave()"><a href="category.aspx?cat=生活秀"><b>生活秀</b></a></td><td class='ltsep'>|</td></tr>
</table>
<table width="776" height="1" align='center' border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
  <tr>
    <td>
</td>
  </tr>
</table>
<table width="776" align="center" border="0" bgcolor="#FFFAFF">
<tr>
<td>
<a href="index.aspx">首页</a>→
<xsl:element name="a">
<xsl:attribute name="href">
category.aspx?cat=
<xsl:value-of select="分类"/>
</xsl:attribute>
<xsl:value-of select="分类"/>
</xsl:element>

<xsl:value-of select="标题"/>
</td>
</tr>
</table>
<table width="776" height="1" align='center' border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
  <tr>
    <td>
</td>
  </tr>
</table>
<table width="776" align="center" border="0" bgcolor="#ffffff">
<tr>
<td>
<xsl:element name="img">
<xsl:attribute name="src"><xsl:value-of select="图片"/></xsl:attribute>
<xsl:attribute name="align"><xsl:value-of select="图片对齐"/></xsl:attribute>
</xsl:element>
<b>标题:</b>
<xsl:value-of select="标题"/><br/><br/>
<b>内容:</b>
<xsl:value-of select="内容"/><br/><br/>
<b>相关链接:</b>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="相关链接"/>
</xsl:attribute>
<xsl:value-of select="来自"/>
</xsl:element><br/><br/>
<b>录入时间:</b>
<xsl:value-of select="录入时间"/><br/><br/>
<xsl:element name="A">
<xsl:attribute name="href">
reply.aspx?filename=
<xsl:value-of select="评论地址"/><br/><br/>
</xsl:attribute>
参与评论/观看评论
</xsl:element>
</td>
</tr>
</table>
<table width="776" align="center" border="0" bgcolor="#FFFAFF">
<tr>
<td align="center">
<b>CopyRight <a href="Myway_Laumailto:Myway_Lau@hotmail.com">Myway_Lau</a>  's site 2005 All Right Reserved</b>
</td>
</tr>
</table>
</body>
</head>
</xsl:for-each>
</html>




谢谢观看和回复 :)

4 个解决方案

#1


大家帮忙看看吧 :)

#2


内容你可以放
<textarea><xsl:value-of select="内容"/></textarea>里,就象本站

#3


谢谢E章大哥,以前看了您很多的教程,受益匪浅!

#4


]]>

#1


大家帮忙看看吧 :)

#2


内容你可以放
<textarea><xsl:value-of select="内容"/></textarea>里,就象本站

#3


谢谢E章大哥,以前看了您很多的教程,受益匪浅!

#4


]]>