小编swi*_*fty的帖子

在 xslt 3.0 中使用累加器无法正常工作

我有一个 XML,其中有一个带有标题、价格、作者、附加价格、艺术家、国家等属性的书籍列表。 XML 如下所示。

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <additionalprice>12.90</additionalprice>
    <year>1985</year>
  </cd>
  <cd>
    <title>Hide your heart</title>
    <artist>Bonnie Tyler</artist>
    <country>UK</country>
    <company>CBS Records</company>
    <price>9.90</price>
    <additionalprice>10.90</additionalprice>
    <year>1988</year>
  </cd>
Run Code Online (Sandbox Code Playgroud)

等等

我想编写一个应用于 XML 的 XSLT 3.0 来获取 HTML。我想使用累加器来获取目录中的书籍总数。尽管有更好的方法,但我只是想使用累加器进行练习,并在包含标题、作者和总价的书籍的表格末尾打印总数。对于填写标题和作者,我使用了 for-each。总价=价格+附加价格。我想使用 iterate 来归档总价。任何人都可以帮我解决这个问题。我不完整的样式表如下所示:

<?xml version="3.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html> 
<body>
  <h2>My CD Collection</h2>
  <table border="2">
    <tr bgcolor="#9acd32">
       <th style="text-align:left">Title</th>
       <th style="text-align:left">Artist</th>
       <th style="text-align:left">Total Price</th>
    </tr>
 <xsl:accumulator name="total" as="xs:integer" initial-value="0" streamable="no">
    <xsl:accumulator-rule match="title" select="$value+1"/>
 </xsl:accumulator>
    <xsl:for-each select="catalog/cd">
     <tr> …
Run Code Online (Sandbox Code Playgroud)

xml xslt xslt-3.0

1
推荐指数
1
解决办法
1623
查看次数

标签 统计

xml ×1

xslt ×1

xslt-3.0 ×1