发现以下 xsl/xml 问题在回答时需要帮助。将其视为挑战。问题:1-获取每个大陆的平均值(格式-编号“###,###.00”),
2-每批次的总数,应该从高到低排序,
3-最昂贵的批次刚刚
列出试图获得一些模板(如下)请帮助提出一个模板,该模板将运行以产生所需的结果总批次(最高到最低)=
每个大陆的平均值=###.00 = 昂贵批次的前三名=
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="factory.xslt"?>
<factory>
<branch>
<continent>North America</continent>
<location>usa</location>
<address>671 fourth avenue</address>
<batch>
<car_make>
<name>toyota</name>
<number_of_makes>20</number_of_makes>
<price_per_make>12000</price_per_make>
</car_make>
</batch>
<batch>
<car_make>
<name>opel</name>
<number_of_makes>5</number_of_makes>
<price_per_make>10000</price_per_make>
</car_make>
</batch>
</branch>
<branch>
<continent>Europe</continent>
<location>france</location>
<address>671 paris</address>
<batch>
<car_make>
<name>nissan</name>
<number_of_makes>10</number_of_makes>
<price_per_make>20000</price_per_make>
</car_make>
</batch>
</branch>
<branch>
<continent>North America</continent>
<location>detroit</location>
<address>45 parklane</address>
<batch>
<car_make>
<name>doge</name>
<number_of_makes>40</number_of_makes>
<price_per_make>35000</price_per_make>
</car_make>
</batch>
<batch>
<car_make>
<name>cadillac</name>
<number_of_makes>20</number_of_makes>
<price_per_make>14000</price_per_make>
</car_make>
</batch>
</branch>
<branch>
<continent>Europe</continent>
<location>germany</location>
<address>675 berlin avenue</address>
<batch>
<car_make>
<name>opel</name>
<number_of_makes>42</number_of_makes>
<price_per_make>19000</price_per_make>
</car_make>
</batch>
<batch>
<car_make>
<name>mercedes</name>
<number_of_makes>20</number_of_makes>
<price_per_make>24000</price_per_make>
</car_make>
</batch>
</branch>
<branch>
<continent>North America</continent>
<location>texas</location>
<address>46 parkland way</address>
<batch>
<car_make>
<name>hummer</name>
<number_of_makes>30</number_of_makes>
<price_per_make>45000</price_per_make>
</car_make>
</batch>
<batch>
<car_make>
<name>cadillac</name>
<number_of_makes>20</number_of_makes>
<price_per_make>14000</price_per_make>
</car_make>
</batch>
</branch>
<branch>
<continent>Asia</continent>
<location>india</location>
<address>67 new delhi way</address>
<batch>
<car_make>
<name>tata</name>
<number_of_makes>12</number_of_makes>
<price_per_make>25000</price_per_make>
</car_make>
</batch>
<batch>
<car_make>
<name>ford</name>
<number_of_makes>20</number_of_makes>
<price_per_make>20000</price_per_make>
</car_make>
</batch>
</branch>
<branch>
<continent>Asia</continent>
<location>japan</location>
<address>56 yorki avenue</address>
<batch>
<car_make>
<name>mazda</name>
<number_of_makes>40</number_of_makes>
<price_per_make>23000</price_per_make>
</car_make>
</batch>
<batch>
<car_make>
<name>hyundai</name>
<number_of_makes>20</number_of_makes>
<price_per_make>10000</price_per_make>
</car_make>
</batch>
</branch>
<branch>
<continent>Asia</continent>
<location>korea</location>
<address>12 yung </address>
<batch>
<car_make>
<name>skyline</name>
<number_of_makes>14</number_of_makes>
<price_per_make>18000</price_per_make>
</car_make>
</batch>
<batch>
<car_make>
<name>toyota</name>
<number_of_makes>40</number_of_makes>
<price_per_make>12000</price_per_make>
</car_make>
</batch>
</branch>
<branch>
<continent>Europe</continent>
<location>england</location>
<address>56 parklane</address>
<batch>
<car_make>
<name>bentely</name>
<number_of_makes>24</number_of_makes>
<price_per_make>50000</price_per_make>
</car_make>
</batch>
<batch>
<car_make>
<name>ferrari</name>
<number_of_makes>10</number_of_makes>
<price_per_make>120000</price_per_make>
</car_make>
</batch>
</branch>
</factory>
以下是xslt 1.0版
<xsl:template match="/*">
TOTAL BATCH:-<a>
$<xsl:call-template name="sumProducts">
<xsl:with-param name="pNodes" select="/*/*/*/batch"/>
<xsl:with-param name="pName1" select="'number_of_make'"/>
<xsl:with-param name="pName2" select="'price_per_make'"/>
</xsl:call-template>
</a><br/>
</xsl:template>
<xsl:template name="sumProducts">
<xsl:param name="pNodes"/>
<xsl:param name="pName1"/>
<xsl:param name="pName2"/>
<xsl:param name="pAccum" select="0"/>
<xsl:choose>
<xsl:when test="not($pNodes)">
<xsl:value-of select="$pAccum"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="sumProducts">
<xsl:with-param name="pNodes" select="$pNodes[position() >1]"/>
<xsl:with-param name="pName1" select="$pName1"/>
<xsl:with-param name="pName2" select="$pName2"/>
<xsl:with-param name="pAccum" select="$pAccum + $pNodes[1]/*[name()=$pName1] * $pNodes[1]/*[name()=$pName2]"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="TotalPrice">
<xsl:param name="pList"/>
<xsl:param name="pRunningTotal" select="0"/>
<xsl:choose>
<xsl:when test="$pList">
<xsl:variable name="varMapPath" select="$pList[1]"/>
<xsl:call-template name="TotalPrice">
<xsl:with-param name="pList" select="$pList[position() > 1]"/>
<xsl:with-param name="pRunningTotal"
select="$pRunningTotal + $varMapPath/productpriceperunit * $varMapPath/productsordered"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$pRunningTotal"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>