【问题标题】:xml namespaces in xsl transform - ignore blank?xsl 转换中的 xml 命名空间 - 忽略空白?
【发布时间】:2011-01-04 17:10:39
【问题描述】:

我是 xsl 新手,正在尝试编写一个模板来将 xml 转换为 html。

我有一个开始的 xml 文档

<?xml version="1.0" encoding="UTF-8"?>
 <data xmlns:autn="http://schemas.com/aci/" 
 xmlns="http://iptc.org/std/nar/2006-10-01/">
  <name>Bob</name>

我的 xsl 模板开始

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"      
xmlns:autn="http://schemas.autonomy.com/aci/">
<xsl:output method="html" omit-xml-declaration="yes"/>
<xsl:template match="/"> 
...
<body>
<p>user name:</p>
<p><xsl:value-of select="data/name"/></p>

问题是,如果我这样做 对于 select 的值,我没有得到任何回报。

如果我这样做 我得到了“鲍勃”,但我失去了所有的 html。

我错过了什么?

【问题讨论】:

    标签: templates xslt


    【解决方案1】:

    您缺少 XML 文档的默认命名空间:

    xmlns="http://iptc.org/std/nar/2006-10-01/"
    

    也将其添加到 XSLT:

    <xsl:stylesheet version="1.0" 
      xmlns:mynamespace="http://iptc.org/std/nar/2006-10-01/"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"      
      xmlns:autn="http://schemas.autonomy.com/aci/">
    

    并在xsl:value-of 中使用该命名空间:

    <xsl:value-of select="mynamespace:data/mynamespace:name" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      • 2015-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多