|
Subject: [xsl] Calculating cumulative values From: "Simon Shutter" <simon@xxxxxxxxxxx> Date: Sat, 3 Feb 2007 13:44:26 -0800 |
Hello,
Here is a tricky (to me) problem that requires looping over several sets and
calculating cumulative values (y2) from x and y1. That is, for each x, set
y2 to be equal to the cumulative value of y1 as shown in the example output
below.
I made my best attempt with the stylesheet below, which I know is quite
incorrect but wanted to show I did actually try to solve the problem. I am
now bogged down with the use of the variable element.
Any assistance would be greatly appreciated,
Simon
---------------------------------------------
Input
---------------------------------------------
<root id="theroot">
<set id="1">
<point x="1" y1="2" />
<point x="1" y1="3" />
<point x="1" y1="0" />
<point x="1" y1="2" />
<point x="1" y1="2" />
<point x="2" y1="3" />
<point x="2" y1="0" />
<point x="2" y1="2" />
<point x="3" y1="2" />
<point x="3" y1="3" />
<point x="3" y1="1" />
<point x="3" y1="2" />
<point x="3" y1="2" />
</set>
<set id="2">
<point x="1" y1="2" />
<point x="1" y1="3" />
<point x="1" y1="0" />
<point x="1" y1="2" />
<point x="2" y1="2" />
<point x="3" y1="2" />
<point x="3" y1="2" />
<point x="3" y1="2" />
</set>
<set id="n">
<point x="1" y1="2" />
<point x="1" y1="3" />
<point x="1" y1="2" />
<point x="2" y1="3" />
<point x="2" y1="0" />
<point x="2" y1="2" />
<point x="3" y1="3" />
</set>
</root>
---------------------------------------------
Desired output
---------------------------------------------
<root id="theroot">
<set id="1">
<point x="1" y1="2" y2="2"/>
<point x="1" y1="3" y2="5"/>
<point x="1" y1="0" y2="5"/>
<point x="1" y1="2" y2="7"/>
<point x="1" y1="2" y2="9"/>
<point x="2" y1="3" y2="3"/>
<point x="2" y1="0" y2="3"/>
<point x="2" y1="2" y2="5"/>
<point x="3" y1="2" y2="2"/>
<point x="3" y1="3" y2="5"/>
<point x="3" y1="1" y2="6"/>
<point x="3" y1="2" y2="8"/>
<point x="3" y1="2" y2="10"/>
</set>
<set id="2">
<point x="1" y1="2" y2="2"/>
<point x="1" y1="3" y2="5"/>
<point x="1" y1="0" y2="5"/>
<point x="1" y1="2" y2="7"/>
<point x="2" y1="2" y2="2"/>
<point x="3" y1="2" y2="2"/>
<point x="3" y1="2" y2="4"/>
<point x="3" y1="2" y2="6"/>
</set>
<set id="n">
<point x="1" y1="2" y2="2"/>
<point x="1" y1="3" y2="5"/>
<point x="1" y1="2" y2="7"/>
<point x="2" y1="3" y2="3"/>
<point x="2" y1="0" y2="3"/>
<point x="2" y1="2" y2="5"/>
<point x="3" y1="3" y2="3"/>
</set>
</root>
---------------------------------------------
Prototype stylesheet - just to show I tried
---------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="tempy" select="5"/>
<!-- Convert root and all elements tags 'as is' -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//point">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:for-each select="@y1">
<xsl:attribute name="y2">
<xsl:choose>
<xsl:when test=". > $tempy">
<xsl:value-of select="$tempy * ."/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$tempy + ."/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Stopping any processing i, Martin Honnen | Thread | Re: [xsl] Calculating cumulative va, Andrew Welch |
| Re: [xsl] Stopping any processing i, David Carlisle | Date | Re: [xsl] Is xsltproc 2.0 compliant, M. David Peterson |
| Month |