XSL 文件使用 xml 数据创建 SVG 图表

问题描述 投票:0回答:1

iam 目前正在尝试通过 xsl 文件将 xml 报告转换为 html(到目前为止效果很好!),然后通过 xslt-fo 将 html 转换为 pdf。

我想使用 xml 文件中的一些数据创建一个 svg 饼图,但我一直坚持让它工作。

谁能告诉我我做错了什么?

我的 XSL 文件:(拉出)

<!-- create variables -->
<xsl:variable name="allHits" select="count(//chapter/hit)" />
<xsl:variable name="allCrits" select="count(//chapter/hit[@class='critical'])" />
<xsl:variable name="allOK" select="count(//chapter/hit[@class='normal'])" />    
<xsl:variable name="allWarning" select="count(//chapter/hit[@class='warning'])" />

<svg height="300" width="300" viewBox="0 0 20 20"> 
                    <circle r="10" cx="10" cy="10" fill="green" />
                    <circle r="5" cx="10" cy="10" fill="transparent"
                        stroke="tomato"
                        stroke-width="10"
                        stroke-dasharray="calc(50 * 31.42 / 100) 31.42"
                        transform="rotate(-90) translate(-20)"
                    />
                    <circle r="5" cx="10" cy="10" fill="transparent"
                        stroke="yellow"
                        stroke-width="10"
                        stroke-dasharray="calc(50* 31.42 / 100) 31.42"
                        
                    />
                    </svg>



郑重声明,我的变量是相互制约的:

allHits = allCrits + allOK + allWarning

到目前为止,这个“有效”,我有一个包含 3 个切片的静态 SVG 饼图。但现在我想将我的 Viarables 放入 svg 中:

<!-- create variables -->
<xsl:variable name="allHits" select="count(//chapter/hit)" />
<xsl:variable name="allCrits" select="count(//chapter/hit[@class='critical'])" />
<xsl:variable name="allOK" select="count(//chapter/hit[@class='normal'])" />    
<xsl:variable name="allWarning" select="count(//chapter/hit[@class='warning'])" />

<svg height="300" width="300" viewBox="0 0 20 20"> 
                    <circle r="10" cx="10" cy="10" fill="green" />
                    <circle r="5" cx="10" cy="10" fill="transparent"
                        stroke="tomato"
                        stroke-width="10"
                        stroke-dasharray="calc(<xsl:copy-of select="$allCrits" />* 31.42 / 100) 31.42"
                        transform="rotate(-90) translate(-20)"
                    />
                    <circle r="5" cx="10" cy="10" fill="transparent"
                        stroke="yellow"
                        stroke-width="10"
                        stroke-dasharray="calc( <xsl:copy-of select="$allWarning" /> * 31.42 / 100) 31.42"
                        
                    />
                    </svg>



现在我的 html 网站只是空白。我究竟做错了什么?我已经在我的 html 中使用上述语句多次访问变量,没有错误。

提前致谢!

我已经尝试了多种方法来调用我的变量,但没有成功

xml svg xslt
1个回答
0
投票

您正在 XSLT 代码中寻找

stroke-dasharray="calc({$allCrits} * 31.42 / 100) 31.42"
形式的属性值模板。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.