2011-11-22 62 views
0

,这是我的XML片状我想从我的XML文件中提取数据,并把它作为链接

<ErrorLog_list> 
<error><download_list>/home/fes/logs/ErrorLog-20111109.gz</download_list></error> 
<error><download_list>/home/fes/logs/ErrorLog-20111110.gz</download_list></error> 
<error><download_list>/home/fes/logs/ErrorLog-20111114.gz</download_list></error> 
</ErrorLog_list> 

我想要做的就是创建一个指向error/download_list

,所以我有一个链接使用该标签

<a href="{ErrorLog_list/error/download_list}"><xsl:value-of select="Title"/></a><br/> 

,但它不工作...

我意识到,问题可能出因为它被声明为 - xmlns attributes are not interpreted as attribute value templates

我的问题是,如何更改我的命名空间以使用上述方法?任何帮助,将不胜感激。

请忽略我的疏忽。 谢谢

+0

感谢编辑 – jayant

+0

我看不出有任何的xmlns,但在这里,我的回答可以帮助:http://stackoverflow.com/questions/7920450/xhtml-to-xml-xslt-conversion/7920612# 7920612 –

+0

xmlns:xsl =“http://www.w3.org/1999/XSL/Transform” – jayant

回答

0

我们应该有整个XML文件作出完整的答案,但这里是我可以说。

既然你写<xsl:value-of select="Title"/>,但我们看不到任何Title元素,我想我们是在包含Title和包含ErrorLog_list的元素相匹配的模板规则。

因此,当您使用属性值模板{ErrorLog_list/error/download_list}时,您尝试获取带有XPath的所有download_list。我猜想返回的节点集合将被协调为一个字符串值,因此将使用节点集合的第一个值,而不是其他节点集合。

您应该使用for-each或制定一个匹配ErrorLog_list/error/download_list的模板规则。如果你想避免使用属性模板值,你也可以在模板规则体内使用xsl:attribute

<xsl:template match="download_list"> 
    <a> 
     <xsl:attribute name="href"><xsl:value-of select="."/></xsl:attribute> 
     <xsl:value-of select="../../../Title"/> 
    </a> 
</xsl:template> 
相关问题