次のxsl/xmlの質問に答えるには、支援が必要であることがわかりました。質問:1-大陸ごとの平均を(format-number "###、###。00")で取得し、
2-バッチごとに合計し、高いものから低いものへと並べ替える必要があり
ます
。
いくつかのテンプレートを取得しようとしました(以下)必要な結果を生成するために実行されるテンプレートを考え出すのを手伝ってください合計バッチ(最高から最低)=
大陸ごとの平均=###。00=高価なバッチの上位3つ=
<?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>