Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: xslt 2.0 getting two points of a list for interpolation [Thread Next] Re: xslt 2.0 getting two points of a list for interpolationTo: NULL Date: 12/12/2008 6:55:00 PM RolfK wrote:
> yes, we should assume that.
If the P elements are sorted on @X then it should be easy, look for the
last P where @X is less than $X and for the first P where @X is greater
than $X.
The following stylesheet:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:mf="http://example.com/2008/mf"
exclude-result-prefixes="xsd mf">
<xsl:output method="xml" indent="yes"/>
<xsl:function name="mf:find-points" as="element()+">
<xsl:param name="X" as="xsd:integer"/>
<xsl:param name="points" as="element()+"/>
<xsl:sequence
select="$points[xsd:integer(@X) lt $X][last()],
$points[xsd:integer(@X) gt $X][1]"/>
</xsl:function>
<xsl:template match="/">
<result>
<xsl:variable name="root" select="/"/>
<xsl:for-each select="(10, 12, 25, 33, 40, 58)">
<result X="{.}">
<xsl:choose>
<xsl:when test="$root/Line/P[xsd:integer(@X) eq current()]">
<xsl:copy-of select="$root/Line/P[xsd:integer(@X) eq
current()]"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="mf:find-points(., $root/Line/P)"/>
</xsl:otherwise>
</xsl:choose>
</result>
</xsl:for-each>
</result>
</xsl:template>
</xsl:stylesheet>
when run against your XML input sample outputs
<result>
<result X="10">
<P X="10" Y="1.0"/>
</result>
<result X="12">
<P X="10" Y="1.0"/>
<P X="20" Y="2.1"/>
</result>
<result X="25">
<P X="20" Y="2.1"/>
<P X="30" Y="2.2"/>
</result>
<result X="33">
<P X="30" Y="2.2"/>
<P X="40" Y="4.3"/>
</result>
<result X="40">
<P X="40" Y="4.3"/>
</result>
<result X="58">
<P X="50" Y="4.4"/>
<P X="60" Y="3.5"/>
</result>
</result>
--
Martin Honnen
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
