Firefox告诉我“XSLT转换过程中出错:XSLT转换失败。”对于使用以下XSL文件的XML文件:
<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dxp='http://schemas.google.com/analytics/2009'
xmlns:gd='http://schemas.google.com/g/2005'
xmlns:fn='http://www.w3.org/2005/xpath-functions'>
<xsl:output method="html"/>
<xsl:template match="/">
<html><head><title>...</title></head><body>
<table frame='border' rules='all'>
<tr><th>site</th><th>week</th><th>pages</th><th>pageviews</th></tr>
<xsl:for-each select='feeds/feed/week'>
<xsl:for-each-group select='entry' group-by='fn:concat(
if (fn:matches(dxp:dimension[@name="ga:pagePath"]/@value, "^/sales"))
then "/sales"
else "non-/sales",
" referred from ",
if (fn:matches(dxp:dimension[@name="ga:referralPath"]/@value, "^/forsale"))
then "/forsale"
else "non-/forsale"
)'>
<tr>
<td><xsl:value-of select='../dxp:tableName'/></td>
<td>
<xsl:value-of select='../dxp:startDate'/>-<xsl:value-of select='../dxp:endDate'/>
</td>
<td><xsl:value-of select='current-grouping-key()'/></td>
<td><xsl:value-of select="sum(current-group()/dxp:metric/@value)"/></td>
</tr>
</xsl:for-each-group>
</xsl:for-each>
</table></body></html>
</xsl:template>
</xsl:stylesheet>
我无法弄清楚这可能是什么问题。有人知道吗?
(显然,如果我需要进一步的信息以便有人能够回答这个问题,我会很高兴提供这些信息:请评论要求它。我甚至不知道可能会有什么样的信息很有帮助。)
编辑:有人在答案中提到我的XML文件可能会有所帮助。它很长,但它的一般结构是:
<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet type='text/xsl' href='./foo.xsl'?>
<feeds xmlns:dxp='http://schemas.google.com/analytics/2009'
xmlns:gd='http://schemas.google.com/g/2005' >
<feed><week>
<id>http://www.google.com/analytics/feeds/data?ids=ga:bar&dimensions=ga:pagePath,ga:referralPath&metrics=ga:pageviews&filters=ga:medium%3D@referral&start-date=2011-12-11&end-date=2011-12-17</id>
<link rel='self' type='application/atom+xml' href='https://www.google.com/analytics/feeds/data?max-results=10&end-date=2011-12-17&start-date=2011-12-11&metrics=ga%3Apageviews&ids=ga%3Abar&dimensions=ga%3ApagePath%2Cga%3AreferralPath&filters=ga%3Amedium%3D%40referral'/>
<link rel='next' type='application/atom+xml' href='https://www.google.com/analytics/feeds/data?start-index=11&max-results=10&end-date=2011-12-17&start-date=2011-12-11&metrics=ga%3Apageviews&ids=ga%3Abar&dimensions=ga%3ApagePath%2Cga%3AreferralPath&filters=ga%3Amedium%3D%40referral'/>
<dxp:metric confidenceInterval='0.0' name='ga:pageviews' type='integer' value='9999'/>
<dxp:tableName>bar</dxp:tableName>
<dxp:endDate>2011-12-17</dxp:endDate>
<dxp:startDate>2011-12-11</dxp:startDate>
<entry gd:etag='W/"baz."' gd:kind='analytics#datarow'>
<dxp:dimension name='ga:pagePath' value='/'/>
<dxp:dimension name='ga:referralPath' value='/'/>
<dxp:metric confidenceInterval='0.0' name='ga:pageviews' type='integer' value='999'/>
</entry>
<entry gd:etag='W/"baz."' gd:kind='analytics#datarow'>
<dxp:dimension name='ga:pagePath' value='/'/>
<dxp:dimension name='ga:referralPath' value='/xyzzy1'/>
<dxp:metric confidenceInterval='0.0' name='ga:pageviews' type='integer' value='999'/>
</entry>
</week>
</feed>
<feed><week>
<id>http://www.google.com/analytics/feeds/data?ids=ga:bar2&dimensions=ga:pagePath,ga:referralPath&metrics=ga:pageviews&filters=ga:medium%3D@referral&start-date=2011-12-11&end-date=2011-12-17</id>
<link rel='self' type='application/atom+xml' href='https://www.google.com/analytics/feeds/data?max-results=10&end-date=2011-12-17&start-date=2011-12-11&metrics=ga%3Apageviews&ids=ga%3Abar2&dimensions=ga%3ApagePath%2Cga%3AreferralPath&filters=ga%3Amedium%3D%40referral'/>
<link rel='next' type='application/atom+xml' href='https://www.google.com/analytics/feeds/data?start-index=11&max-results=10&end-date=2011-12-17&start-date=2011-12-11&metrics=ga%3Apageviews&ids=ga%3Abar2&dimensions=ga%3ApagePath%2Cga%3AreferralPath&filters=ga%3Amedium%3D%40referral'/>
<dxp:metric confidenceInterval='0.0' name='ga:pageviews' type='integer' value='9999'/>
<dxp:tableName>bar2</dxp:tableName>
<dxp:endDate>2011-12-17</dxp:endDate>
<dxp:startDate>2011-12-11</dxp:startDate>
<entry gd:etag='W/"baz."' gd:kind='analytics#datarow'>
<dxp:dimension name='ga:pagePath' value='/'/>
<dxp:dimension name='ga:referralPath' value='/'/>
<dxp:metric confidenceInterval='0.0' name='ga:pageviews' type='integer' value='999'/>
</entry>
<entry gd:etag='W/"baz."' gd:kind='analytics#datarow'>
<dxp:dimension name='ga:pagePath' value='/'/>
<dxp:dimension name='ga:referralPath' value='/xyzzy2'/>
<dxp:metric confidenceInterval='0.0' name='ga:pageviews' type='integer' value='999'/>
</entry>
</week>
</feed>
</feeds>
答案 0 :(得分:1)
为什么你认为Firefox使用XSLT 2.0处理器?
AFAIK,事实并非如此。
显然,当给定包含非XSLT 1.0指令的XSLT 2.0转换时,XSLT 1.0处理器会引发某种错误,例如<xsl:for-each-group>
。
答案 1 :(得分:0)
你有一个示例xml文件在附近:) 可能有助于调查xsl的错误。
在我第一眼看到的时候,我看到了一个命名空间前缀ga,在xsl的xsl:stylesheet元素的命名空间列表中没有提到。
我还怀疑xsl:for-each-group中的group-by属性是否有效。看起来你试图通过连接一些xpath结果来动态设置group-by属性的值来组成一个xpath表达式。这是不可能的。