以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 XML基础 』  (http://bbs.xml.org.cn/list.asp?boardid=1)
----  字体显示问题!  (http://bbs.xml.org.cn/dispbbs.asp?boardid=1&rootid=&id=45677)


--  作者:冯如松
--  发布时间:4/19/2007 3:52:00 PM

--  字体显示问题!
我有一个滑坡文件的XML,希望使用XSL使之在HTML中显示出来,但是显示后有好多字是不能识别的乱码,请高手帮我看看!小可这里多谢了!
我的XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2005 rel. 3 U (http://www.altova.com) by  () -->
<?xml-stylesheet type="text/xsl" href="D:\xmlxin\slopex.xsl"?>
<Slope xmlns="http://slopedata.com/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slopedata.com/namespace
D:\xmlxin\slopedata.xsd">
 <general>
  <name>漫湾水电站左岸边坡滑坡</name>
  <type>天然边坡</type>
  <character>导致失稳因素为爆破与开挖切脚</character>
  <introduce>漫湾水电站左岸边坡是指坝基、水垫塘左岸以及坝前左岸边坡,左岸边坡结构面发育,其倾角与自然山坡坡角(42度~45度)基本一致,与其它组结构面切割组合,构成了分离块体,水工建筑基础开挖形成了临空面,边坡稳定性差。在勘测工作阶段和施工阶段曾多次发生小范围塌滑现象,其中最大一次是1989年1月7日发生的平面型塌滑,其范围:1024~917m,坝横0+20~0+135m,方量10.6万立方米。边坡塌滑后,曾委托中国水科院、清华大学等单位进行多项科研与研究,使剩余下滑力由70万吨优化至44万吨。采用削坡减载,预应力锚索,锚硐、锚桩、作坡面喷混凝土保护以及表层、深层排水,加强观测等综合治理措施。至目前为止边坡加固处理措施。至目前为止边坡加固处理工作基本结束。经监测资料证明,经加固处理后边坡稳定.</introduce>
  <photo/>
 </general>
 <geology>
  <basic/>
  <RMRSMR/>
  <joint/>
  <description/>
  <drawing/>
 </geology>
 <geochar>
  <rocktest/>
  <jointtest/>
  <groundstress/>
  <soiltest/>
 </geochar>
 <design>
  <design/>
  <manipulation/>
  <drawing/>
 </design>
 <cutburst>
  <basic/>
  <wavevelocity/>
 </cutburst>
 <monitor>
  <equipment/>
  <arrangement/>
  <dataconsequence/>
  <waterdata/>
  <grounddata/>
  <others/>
 </monitor>
 <damage>
  <basicinf/>
  <damagedes/>
  <damdrawing/>
 </damage>
 <reference>
  <inner/>
  <publication/>
  <picture/>
 </reference>
</Slope>

我的XSL文件:
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/REC-html40">
 <xsl:output method="html"/>
 <xsl:template match="/">
  <html>
   <head>
    <title>data document of landslide</title>
    <style type="text/css">
     <xsl:comment>
            span.literal         { font-family: Courier, monospace; }
          </xsl:comment>
    </style>
   </head>
   <body>
    <h1>data document of landslide</h1>
    <p>The structure of landslide document (as defined by
          the landslide classificate standard) is outlined below.</p>
    <table cellspacing="5" cellpadding="2" border="0">
     <tr>
      <td colspan="8">
       <b>Node types:</b>
      </td>
     </tr>
     <tr>
      <td bgcolor="#99CCCC">
       <b>basic</b>
      </td>
      <td bgcolor="#99CCCC">
       <b>geology</b>
      </td>
      <td bgcolor="#CCCC99">
       <b>geochar</b>
      </td>
      <td bgcolor="#FFFF99">
       <b>design</b>
      </td>
      <td bgcolor="#FFCC99">
       <b>cutbrust</b>
      </td>
      <td bgcolor="#CCCCFF">
       <b>monitor</b>
      </td>
      <td bgcolor="#99FF99">
       <b>damage</b>
      </td>
      <td bgcolor="#CC99CC">
       <b>reference</b>
      </td>
     </tr>
    </table>
    <br/>
    <table width="100%" border="1" bgcolor="#99CCCC" cellspacing="2">
     <tr bgcolor="#99CCCC">
      <td colspan="2">
       <b>滑坡数据文件</b>
      </td>
     </tr>
     <xsl:for-each select="namespace::*">
      <tr bgcolor="#CC99CC">
       <td width="15">   </td>
       <td>
        <xsl:call-template name="namespace-node"/>
       </td>
      </tr>
     </xsl:for-each>
     <xsl:for-each select="*|comment()|processing-instruction()|text()">
      <tr bgcolor="#99CCCC">
       <td width="15">   </td>
       <td>
        <xsl:apply-templates select="."/>
       </td>
      </tr>
     </xsl:for-each>
    </table>
   </body>
  </html>
 </xsl:template>
 <xsl:template match="text()">
  <xsl:if test="string-length(normalize-space(.))">
   <tr>
    <td bgcolor="#CCCC99" width="15">    </td>
    <td bgcolor="#FFCC99" width="100%">
     <b>  </b>
     <span class="literal">
      <xsl:value-of select="."/>
     </span>
    </td>
   </tr>
  </xsl:if>
 </xsl:template>
 <xsl:template match="*">
  <table border="1" width="100%" cellspacing="2">
   <xsl:choose>
    <xsl:when test="count(@*) &gt; 0">
     <tr>      </tr>
    </xsl:when>
    <xsl:otherwise>
     <tr>
      <td bgcolor="#CCCC99" colspan="2">
       <b>  </b>
       <span class="literal">
        <xsl:text>  </xsl:text>
        <xsl:value-of select="name()"/>
        <xsl:text>  </xsl:text>
       </span>
      </td>
     </tr>
    </xsl:otherwise>
   </xsl:choose>
   <xsl:for-each select="namespace::*">
    <tr>
     <td bgcolor="#CCCC99" width="15">    </td>
     <td bgcolor="#CC99CC">
         
          </td>
    </tr>
   </xsl:for-each>
   <xsl:for-each select="*|comment()|processing-instruction()|text()">
    <tr bgcolor="#CCCC99">
     <td width="15">   </td>
     <td>
      <xsl:apply-templates select="."/>
     </td>
    </tr>
   </xsl:for-each>
  </table>
 </xsl:template>
</xsl:stylesheet>

用html显示后:中间的一段文字变成了:
漟??水电站左岸边坡是指坝基㟦??垫塘左岸以及坝前左岸边坡,左岸边坡结构面发育,其埨??与臟??山坡坡蟯?_2度~45度)基本丟??,与其它组结构面切割组合,构成了分知??体,水工建筑基硟??挖形成了临空靟??边坡稳定性差。在勘测工作阶查??施工阶段曾多查??生小范围埦??现象,其中期??丟_星989幟期日发生的平面型埦??,其范围:1024~917m,坝樟+20~0+135m,方釟0.6万立方米。边坡埦??后,曾委托丟??水矩?__清华大埧??单位进行埩??矧??与研究,使剩余下滑力由70万吨优化臟4万吨。采用削坡减载,预应力锚紟??锚矣??锚桩㟤??坡面喷混凝土保护以及表层㟦??层排水,加强蟦??等综合治理掟??。至盟??为柨??坡加固处理掟??。至盟??为柨??坡加固处理工作基本结束。经监测资料证明,经加固处理后边坡稳実

好多不能辨认的乱码,这个问题怎么解决啊?请高手指点一二!感激涕零!!!


--  作者:Qr
--  发布时间:4/20/2007 12:42:00 PM

--  
XML的encoding和XSL的encoding都要统一编码,另外,保存文件时,编码类型也要适用于encoding的类型。
--  作者:冯如松
--  发布时间:4/20/2007 9:24:00 PM

--  
XML和XSL的encoding都设为gb2312,在显示的时候仍然是上面的结果。“保存文件时,编码类型也要适用于encoding的类型”这一点在那里能检查和设置?
谢谢QR老兄指教!!!
--  作者:Qr
--  发布时间:4/21/2007 10:24:00 AM

--  
偶没用XMLSpy,也不知道在哪改,偶主要是通过程序生成和调用XML。将下面的代码COPY到记事本中直接保存即可。真的是编码的问题。

<?xml version="1.0" encoding="gb2312"?>
<!-- edited with XMLSpy v2005 rel. 3 U (http://www.altova.com) by  () -->
<?xml-stylesheet type="text/xsl" href="1.xsl"?>
<Slope xmlns="http://slopedata.com/namespace"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://slopedata.com/namespace
D:\xmlxin\slopedata.xsd">
<general>
  <name>漫湾水电站左岸边坡滑坡</name>
  <type>天然边坡</type>
  <character>导致失稳因素为爆破与开挖切脚</character>
  <introduce>漫湾水电站左岸边坡是指坝基、水垫塘左岸以及坝前左岸边坡,左岸边坡结构面发育

,其倾角与自然山坡坡角(42度~45度)基本一致,与其它组结构面切割组合,构成了分离块体,水

工建筑基础开挖形成了临空面,边坡稳定性差。在勘测工作阶段和施工阶段曾多次发生小范围塌滑现

象,其中最大一次是1989年1月7日发生的平面型塌滑,其范围:1024~917m,坝横0+20~0+135m,方量

10.6万立方米。边坡塌滑后,曾委托中国水科院、清华大学等单位进行多项科研与研究,使剩余下滑

力由70万吨优化至44万吨。采用削坡减载,预应力锚索,锚硐、锚桩、作坡面喷混凝土保护以及表层

、深层排水,加强观测等综合治理措施。至目前为止边坡加固处理措施。至目前为止边坡加固处理工

作基本结束。经监测资料证明,经加固处理后边坡稳定.</introduce>
  <photo/>
</general>
<geology>
  <basic/>
  <RMRSMR/>
  <joint/>
  <description/>
  <drawing/>
</geology>
<geochar>
  <rocktest/>
  <jointtest/>
  <groundstress/>
  <soiltest/>
</geochar>
<design>
  <design/>
  <manipulation/>
  <drawing/>
</design>
<cutburst>
  <basic/>
  <wavevelocity/>
</cutburst>
<monitor>
  <equipment/>
  <arrangement/>
  <dataconsequence/>
  <waterdata/>
  <grounddata/>
  <others/>
</monitor>
<damage>
  <basicinf/>
  <damagedes/>
  <damdrawing/>
</damage>
<reference>
  <inner/>
  <publication/>
  <picture/>
</reference>
</Slope>

<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/REC-html40">
<xsl:output method="html"/>
<xsl:template match="/">
  <html>
   <head>
    <title>data document of landslide</title>
    <style type="text/css">
     <xsl:comment>
            span.literal         { font-family: Courier, monospace; }
          </xsl:comment>
    </style>
   </head>
   <body>
    <h1>data document of landslide</h1>
    <p>The structure of landslide document (as defined by
          the landslide classificate standard) is outlined below.</p>
    <table cellspacing="5" cellpadding="2" border="0">
     <tr>
      <td colspan="8">
       <b>Node types:</b>
      </td>
     </tr>
     <tr>
      <td bgcolor="#99CCCC">
       <b>basic</b>
      </td>
      <td bgcolor="#99CCCC">
       <b>geology</b>
      </td>
      <td bgcolor="#CCCC99">
       <b>geochar</b>
      </td>
      <td bgcolor="#FFFF99">
       <b>design</b>
      </td>
      <td bgcolor="#FFCC99">
       <b>cutbrust</b>
      </td>
      <td bgcolor="#CCCCFF">
       <b>monitor</b>
      </td>
      <td bgcolor="#99FF99">
       <b>damage</b>
      </td>
      <td bgcolor="#CC99CC">
       <b>reference</b>
      </td>
     </tr>
    </table>
    <br/>
    <table width="100%" border="1" bgcolor="#99CCCC" cellspacing="2">
     <tr bgcolor="#99CCCC">
      <td colspan="2">
       <b>滑坡数据文件</b>
      </td>
     </tr>
     <xsl:for-each select="namespace::*">
      <tr bgcolor="#CC99CC">
       <td width="15">   </td>
       <td>
        <!--xsl:call-template name="namespace-node"/--><!--因为代码中没有模板,只里注释掉了-->
       </td>
      </tr>
     </xsl:for-each>
     <xsl:for-each select="*|comment()|processing-instruction()|text()">
      <tr bgcolor="#99CCCC">
       <td width="15">   </td>
       <td>
        <xsl:apply-templates select="."/>
       </td>
      </tr>
     </xsl:for-each>
    </table>
   </body>
  </html>
</xsl:template>
<xsl:template match="text()">
  <xsl:if test="string-length(normalize-space(.))">
   <tr>
    <td bgcolor="#CCCC99" width="15">    </td>
    <td bgcolor="#FFCC99" width="100%">
     <b>  </b>
     <span class="literal">
      <xsl:value-of select="."/>
     </span>
    </td>
   </tr>
  </xsl:if>
</xsl:template>
<xsl:template match="*">
  <table border="1" width="100%" cellspacing="2">
   <xsl:choose>
    <xsl:when test="count(@*) &gt; 0">
     <tr>      </tr>
    </xsl:when>
    <xsl:otherwise>
     <tr>
      <td bgcolor="#CCCC99" colspan="2">
       <b>  </b>
       <span class="literal">
        <xsl:text>  </xsl:text>
        <xsl:value-of select="name()"/>
        <xsl:text>  </xsl:text>
       </span>
      </td>
     </tr>
    </xsl:otherwise>
   </xsl:choose>
   <xsl:for-each select="namespace::*">
    <tr>
     <td bgcolor="#CCCC99" width="15">    </td>
     <td bgcolor="#CC99CC">
         
          </td>
    </tr>
   </xsl:for-each>
   <xsl:for-each select="*|comment()|processing-instruction()|text()">
    <tr bgcolor="#CCCC99">
     <td width="15">   </td>
     <td>
      <xsl:apply-templates select="."/>
     </td>
    </tr>
   </xsl:for-each>
  </table>
</xsl:template>
</xsl:stylesheet>


--  作者:冯如松
--  发布时间:4/21/2007 5:08:00 PM

--  
谢谢QR老兄的指点,我明白了。
再次感谢您!但是您的博客好像登陆不了,希望有机会我这只菜鸟能当面请教!
十分欣赏您的这句话“授人予鱼不如授人予渔”,你是老师吗?是那个学校的?
--  作者:Qr
--  发布时间:4/21/2007 8:36:00 PM

--  
偶的博客应该可以登录的啊,就是本站的博客站点啊,如不行,可以http://bbs.w3china.org/blog/blog.asp?name=Qr方式访问,只是最近比较忙,没多少时间来更新。
“授人予鱼不如授人予渔”,这句话偶也喜欢,但是似乎比较难做到哦。有些网友总喜欢点名要答案,偶不大喜欢。你高看偶了,偶不是老师,要是偶当了老师,学生们可能都会变成反动派滴,呵呵。
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
94.238ms