数学.下一个父级项目XSLT 1.0中的一个孩子从Anotehr中减去一个孩子



我需要通过节点循环并在父母节点上具有数学功能。

我已经和父母一起玩了::祖先::等,但是我无法得到我需要的东西。

我已经简化了XML和XSL的此示例。

<bookstore>
<book>
    <title lang="en">Harry Potter</title>
    <price>29.99</price>
</book>
<book>
    <title lang="en">Learning XML</title>
    <price>39.95</price>
</book>
<book>
    <title lang="en">Lord Of The Rings</title>
    <price>32.99</price>
</book>

我需要输出在表(XSL:FO(

哈利·波特29.99 29.99学习XML 39.95 -9.96指环王32.99 -6.96

基本上显示的是标题,价格,总和(当前节点的价格 - 上一个节点的价格(因此,第2行的最后一个单元格是(39.95-29.99(第3行是(32.99-39.95(我有前两列,但我不知道如何在循环中完成最后一列。

这是我要创建

的桌子的片段
<xsl:for-each select="/bookstore">
<fo:table-row border-top="0.5pt solid black">
    <fo:table-cell <!--%var-cell-padding%-->>
        <fo:block>
            <xsl:value-of select="title" />
        </fo:block>
    </fo:table-cell>
    <fo:table-cell <!--%var-cell-padding%--> text-align="left">
        <fo:block>
            <xsl:value-of select="price"/>
        </fo:block>
    </fo:table-cell>
    <fo:table-cell <!--%var-cell-padding%--> text-align="center">
        <fo:block>
            <xsl:value-of select="currentprice-previousItemInLoopPrice"/>
        </fo:block>
    </fo:table-cell>
</fo:table-row>

您的数据似乎对您的期望似乎是错误的,但是这是一个简单的示例,其余的XSL fo的其余部分则需要呈现页面:

给定此输入:

<bookstore>
    <book>
        <title lang="en">Harry Potter</title>
        <price>29.99</price>
    </book>
    <book>
        <title lang="en">Learning XML</title>
        <price>39.95</price>
    </book>
    <book>
        <title lang="en">Lord Of The Rings</title>
        <price>32.99</price>
    </book>
</bookstore>

和此XSL(这是100种方法之一(:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
    <xsl:template match="bookstore">
        <fo:table>
            <xsl:apply-templates/>
        </fo:table>
    </xsl:template>
    <xsl:template match="book">
        <fo:table-row>
            <fo:table-cell>
                <fo:block>
                    <xsl:value-of select="title"/>
                </fo:block>
            </fo:table-cell>
            <fo:table-cell>
                <fo:block>
                    <xsl:value-of select="format-number(price,'#.00')"/>
                </fo:block>
            </fo:table-cell>
            <fo:table-cell>
                <fo:block>
                    <xsl:choose>
                        <xsl:when test="not(preceding-sibling::book)">
                            <xsl:text>0.00</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="format-number(number(price) - number(preceding-sibling::book[1]/price), '#.00')"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </fo:block>
            </fo:table-cell>
        </fo:table-row>
    </xsl:template>
</xsl:stylesheet>

输出为:

<fo:table xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:table-row><fo:table-cell><fo:block>Harry Potter</fo:block></fo:table-cell><fo:table-cell><fo:block>29.99</fo:block></fo:table-cell><fo:table-cell><fo:block>0.00</fo:block></fo:table-cell></fo:table-row>
<fo:table-row><fo:table-cell><fo:block>Learning XML</fo:block></fo:table-cell><fo:table-cell><fo:block>39.95</fo:block></fo:table-cell><fo:table-cell><fo:block>9.96</fo:block></fo:table-cell></fo:table-row>
<fo:table-row><fo:table-cell><fo:block>Lord Of The Rings</fo:block></fo:table-cell><fo:table-cell><fo:block>32.99</fo:block></fo:table-cell><fo:table-cell><fo:block>-6.96</fo:block></fo:table-cell></fo:table-row>
</fo:table

最新更新