以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  xml文件里面含有&,<,>等特殊字符,转换的时候怎么解决,谢谢!  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=10064)


--  作者:菜籽
--  发布时间:9/17/2004 10:00:00 AM

--  xml文件里面含有&,<,>等特殊字符,转换的时候怎么解决,谢谢!
xml文件如下:里面含有&,<,>等特殊字符,转换的时候出现问题:
<?xml version="1.0" encoding="GBK"?>
<?xml-stylesheet type="text/xsl" href="xsl.xml"?>
<Question ID="0" ZTMXH="0" KMDM="CCSJ0" TMLX="XZ0">
 <QuestionPart XH="1">
  <TextBlock>题干文本*a=&b,cd,</TextBlock>
  <MediaBlock>题干媒体</MediaBlock>
 </QuestionPart>
 <AnswerPart XH="2" B_ZQDA="false" B_YC="false">
  <TextBlock>答案1文本 </TextBlock>
  <MediaBlock>答案1媒体</MediaBlock>
 </AnswerPart>
 <AnswerPart XH="3" B_ZQDA="false" B_YC="false">
  <TextBlock>答案2文本 </TextBlock>
  <MediaBlock>答案2媒体</MediaBlock>
 </AnswerPart>
 <AnswerPart XH="4" B_ZQDA="false" B_YC="false">
  <TextBlock>答案3文本 </TextBlock>
  <MediaBlock>答案3媒体</MediaBlock>
 </AnswerPart>
 <AnswerPart XH="5" B_ZQDA="true" B_YC="false">
  <TextBlock>答案4文本 </TextBlock>
  <MediaBlock>答案4媒体</MediaBlock>
 </AnswerPart>
</Question>

转换文件如下xsl.xml
<?xml version="1.0" encoding="GBK"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--xsl:output method="html" indent="yes"/ -->
  <xsl:template match="/">
    <html>
    <head><meta http-equiv="content-type" content="text/html; charset=gbk"/></head>
      <body>
   <center>   
    <table border="1">    
     <xsl:for-each select="*">
      <xsl:apply-templates />
     </xsl:for-each>   
    </table>   
    <input type="submit" value="提交" action="/">
    </input>
   </center>
      </body>
    </html>
  </xsl:template>
  
  <xsl:template match="Question">
    <font color="black">子题目代码:<xsl:value-of select="@ID"/></font>
    序号:<xsl:value-of select="@ZTMXH"/>   
    <xsl:for-each select=".">
    <xsl:apply-templates />
    </xsl:for-each>
  </xsl:template>  
  
  <xsl:template match="QuestionPart">
  <tr>
   <td>
      题干:<xsl:value-of select="@XH"/>
     </td>
   <td>
    <xsl:for-each select="TextBlock">
     <xsl:apply-templates />
     </xsl:for-each>
   </td>    
  </tr>
  </xsl:template>  

  <xsl:template match="AnswerPart">  
  <font color="blue">
   <tr>
    <td>
     答案:<xsl:number value = "position()-1" format = "A"/>
     <xsl:if test="@b_zqda='true'">
      <xsl:if test="@b_yc='false'">
       (正确)
      </xsl:if>
     </xsl:if>
     <xsl:if test="@b_zqda='false'">      
      <xsl:if test="@b_yc='false'">
       (错误)
      </xsl:if>     
     </xsl:if>
    </td>    
    <td>      
     <xsl:for-each select="TextBlock">   
      <xsl:apply-templates />   
     </xsl:for-each>

    </td>
   </tr>
  </font>  
  </xsl:template>

  <xsl:template match="MediaPart">
  
   <td>
    <img width="100" height="100">
     <xsl:attribute name="SRC">
      <xsl:for-each select="MediaBlock">
       <xsl:apply-templates />
      </xsl:for-each>
     </xsl:attribute>
    </img>
   </td>
   
  </xsl:template>
  
  <xsl:template match="TextBlock"> 
    <xsl:value-of select ="TextBlock"/>  
  </xsl:template>

  <xsl:template match="MediaBlock"> 
    <xsl:value-of select ="MediaBlock"/>  
  </xsl:template>

</xsl:stylesheet>
转换时出错,错误信息如下:
无法显示 XML 页。
使用 XSL 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。


--------------------------------------------------------------------------------

应有分号。处理资源 'file:///G:/测试xml/9.17/question.xml' 时出错。第 5 行,位置: 23

  <TextBlock>题干文本*a=&b,cd,</TextBlock>
----------------------^
各位有对此问题了解的,请指教,谢谢!


[此贴子已经被作者于2004-9-17 10:25:06编辑过]

--  作者:sam
--  发布时间:9/17/2004 10:26:00 AM

--  
特殊字符需要转义,请参见
http://bbs.xml.org.cn/dispbbs.asp?boardID=8&ID=6501
--  作者:doubleG
--  发布时间:9/17/2004 10:36:00 AM

--  
<TextBlock>题干文本*a=&b,我的99%的时间在睡觉</TextBlock>
——><TextBlock><![CDATA[题干文本*a=&b,我的99%的时间在睡觉]]></TextBlock>

--  作者:菜籽
--  发布时间:9/17/2004 11:41:00 AM

--  
谢谢楼上的两位,好人,真诚的感谢!

W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms