liujia

统计

留言簿(1)

阅读排行榜

评论排行榜

XSLT1中处理含有默认名称空间声明的XML文档时的XPATH问题

XSLT1中使用XPATH对含有默认名称空间声明的XML文档进行查找时是查不出内容的

例如对于
<requestHierarchySelectResult xmlns=http://www.lightcc.com/ns xmlns:cs="http://www.customsolids.com">
   
<request>
       
<created_dt>05/05/2000 00:00:00</created_dt>
       
<created_tm>01/01/1900 14:02:46</created_tm>
       
<cs:request_id>100002</cs:request_id>
   
</request>
</requestHierarchySelectResult>
应用
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 
   xmlns
="http://www.lightcc.com/ns"
   xmlns
:cs="http://www.customsolids.com"
>
   <xsl:template match="/">
      <root><xsl:apply-templates  select
="/*/request"/></root>
   </xsl:template>
   <xsl:template  match="*|@*|node()"/>
   <xsl:template  match="request">
      
<gotHere><xsl:value-of  select="."/></gotHere>
   </xsl:template>
</xsl:stylesheet>
是没有效果的.
需要给默认的名称空间指定一个前缀
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 
   xmlns:lc
="http://www.lightcc.com/ns"
   xmlns
:cs="http://www.customsolids.com"
>
   <xsl:template match="/">
       
<root><xsl:apply-templates  select="/*/lc:request"/></root>
   </xsl:template>
   <xsl:template  match="*|@*|node()"/>
   <xsl:template  match="lc:request">
      
<gotHere><xsl:value-of  select="."/></gotHere>
   </xsl:template>
</xsl:stylesheet>
据说XSLT2和XPATH2会解决这个问题

参考:
   http://www.edankert.com/defaultnamespaces.html
   http://www.topxml.com/people/bosley/defaultns.asp


posted on 2006-07-04 23:43 刘佳 阅读(359) 评论(0)  编辑  收藏 所属分类: XML


只有注册用户登录后才能发表评论。


网站导航: