我有一个类似于XML结构的文件系统,现在我想获取一个节点的“文件路径”。我尝试了以下XSLT,但它不起作用。我只得到这些错误:返回一个节点的所有父节点
警告: XSLTProcessor中:: transformToXml(): 模板:在 C:\用户\卢德格尔\文件\ XAMPP \ htdocs中\ CloudAmp \ devel的\ PHP \ localAudioFileLocationScanner.php 线60上
警告: XSLTProcessor中:: transformToXml():#0 名//文件中 C:\用户\卢德格尔\文件\ XAMPP \ htdocs中\ CloudAmp \ devel的\ PHP \ localAudioFileLocationScanner.php 上line 60
警告: XSLTProcessor中:: transformToXml():#1 名//文件中 C:\用户\卢德格尔\文件\ XAMPP \ htdocs中\ CloudAmp \线60上devel的\ PHP中\ localAudioFileLocationScanner.php
[ ...]
警告:XSLTProcessor中:: transformToXml(): xsltApplyXSLTTemplate:潜在 无限递归模板是检测 。您可以调整xsltMaxDepth (--maxdepth),以便将嵌套模板的最大数量 调用和变量/参数(当前为 设置为3000)提高为 。在 C:\用户\卢德格尔\ DocumentsXA MPP \ htdocs中\ CloudAmp \ devel的\ PHP \ localAudioFileLocationScanner.php 线60上
XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/dir">
<xsl:apply-templates select="@name" />
<xsl:apply-templates select="parent::dir" />
</xsl:template>
<xsl:template match="//file">
<xsl:apply-templates select="@name" />
<xsl:apply-templates select="parent::dir" />
</xsl:template>
</xsl:stylesheet>
源XML:
<root>
<path val="C:/Users/">
<file name="a.txt"/>
<dir name="aaa">
<file name="b.txt"/>
<file name="c.txt"/>
</dir>
<dir name="bbb">
<dir name="ccc">
<file name="d.txt"/>
</dir>
</dir>
</path>
</root>
我无法让它工作。如果你能帮助我,这将是一件好事。
好问题,+1。查看我的答案,获得比其他当前答案更短的完整解决方案(包括模板数量和非空行数量)。 :) – 2011-04-03 22:47:42