最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

包含中文字符的URL編碼問題

 更新時間:2006年10月11日 00:00:00   作者:  

在xml應(yīng)用中,經(jīng)常將一些URL信息作為xml數(shù)據(jù)存儲,其中URL參數(shù)有可能包含有中文字符。當(dāng)使用dom對xml數(shù)據(jù)進行解析時,可以對中文字符進行編碼。
但如果只使用xslt來顯示xml數(shù)據(jù)時(data.xml+data.xsl),發(fā)現(xiàn)此時的URL會出現(xiàn)編碼錯誤.即使指定編碼類型(encoding="gb2312"),依然會出現(xiàn)同樣的問題.
測試發(fā)現(xiàn):是IE的緩存機制問題,IE仍會把新的頁面(所鏈接的URL)的MIME內(nèi)容類型默認為text/xml

解決方法:
1.指定輸出文檔類型為xml文檔  (example:data.xsl)
 <xsl:output method="xml"  encoding="gb2312" media-type="text/xml" />
2.在新的窗口打開,給聯(lián)接增加屬性,指明目標(biāo)窗口為其他窗口  (example:data2.xsl)
 <xsl:attribute name="target">_blank</xsl:attribute>


examples:


/*** data.xml ***/

<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet type="text/xsl" href="data.xsl"?>
<root>
 <search>
  <url>http://www.google.com/search?q=</url>
  <word>xml數(shù)據(jù)</word>
 </search>
 <search>
  <url>http://www1.baidu.com/baidu?word=</url>
  <word>xml數(shù)據(jù)</word>
 </search>
 <search>
  <url>http://www.google.com/search?q=</url>
  <word>極限編程(xp)</word>
 </search>
 <search>
  <url>http://www1.baidu.com/baidu?word=</url>
  <word>極限編程(xp)</word>
 </search>
</root>


/*** data.xsl ***/

<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- 去掉下面一句,將出現(xiàn)錯誤 -->
<xsl:output method="xml"  encoding="gb2312" media-type="text/xml" />

<xsl:template match="/">
 <xsl:apply-templates /> 
</xsl:template>

<xsl:template match="search">
 <xsl:element name="a">
  <xsl:attribute name="href"><xsl:value-of select="url" /><xsl:value-of select="word" /></xsl:attribute>
  <xsl:value-of select="word" />
 </xsl:element>
 <br />
</xsl:template>

</xsl:stylesheet>


/*** data2.xsl ***/

<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
 <xsl:apply-templates /> 
</xsl:template>

<xsl:template match="search">
 <xsl:element name="a">
  <xsl:attribute name="href"><xsl:value-of select="url" /><xsl:value-of select="word" /></xsl:attribute>
  <!-- 去掉下面一句,將出現(xiàn)錯誤 -->
  <xsl:attribute name="target">_blank</xsl:attribute>
  <xsl:value-of select="word" />
 </xsl:element>
 <br />
</xsl:template>

</xsl:stylesheet>


相關(guān)文章

最新評論

潞城市| 新余市| 龙江县| 德格县| 丰宁| 策勒县| 赫章县| 休宁县| 社会| 永善县| 连江县| 崇信县| 原阳县| 曲松县| 乡宁县| 孝昌县| 叙永县| 邢台县| 洪泽县| 阳春市| 罗江县| 丰原市| 建始县| 宝应县| 东台市| 龙泉市| 曲周县| 张家口市| 精河县| 宁波市| 嘉荫县| 韶关市| 新巴尔虎右旗| 井陉县| 噶尔县| 贵港市| 云霄县| 洱源县| 安阳县| 尼玛县| 揭阳市|