开发者

Pass an array of double as a param in xsl

I need your brilliant mind! I have next problem: I have an xsl document and I want to pass an array as a param (or variable) to this xsl to iterate over it.

 <?xml version="1.0" encoding="UTF-8"?>
 <xsl:stylesheet version="1.0" 
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:include href="properties.xsl" />
<xsl:param name="upperLimit" />
<xsl:param name="value" />
<xsl:variable name="array" />
<xsl:template match="/">
    <Chart zdepth="60" exeTime="2" chartOrder="area,column">
        <categories>
            <category label="Jan"/>
            <category label="Feb"/>
            <category label="Mar"/>
            <category label="Apr"/>
            <category label="May"/>
            <category label="Jun"/>
            <category label="Jul"/>
            <category label="Aug"/>
            <category label="Sep"/>
            <category label="Oct"/>
            <category label="Nov"/>
            <category label="Dec"/>
        </categories>
        <dataset seriesName="budget" color="1E90FF" plotBorderColor="1E90FF" renderAs="column">
            <set value="{$value}"/>
            <set value="32800"/>
            <set value="32600"/>
            <set value="29600"/>
            <set value="32600"/>
            <set value="32600"/>
            <set value="31800"/>
            <set value="36700"/>
            <set value="29700"/>
            <set value="31900"/>
            <set value="32900"/>
            <set value="34800"/>
        </dataset>
        <dataset seriesName="sales" color="EE2C2C" plotBorderColor="EE2C2C" renderAs="area">
            <xsl:for-each select="$array">
                <xsl:copy-of select="."/>
            </xsl:for-each>

        </dataset>
        开发者_运维知识库<styles>
            <definition>
                <style name="captionFont" type="font" size="15"/>
            </definition>
            <application>
                <apply toObject="caption" styles="captionfont"/>
            </application>
        </styles>

        <xsl:call-template name="properties"/>

    </Chart>
</xsl:template>

I have element, in which I have elements and I want each have some value from "array". (something like that: , or even in some loop: ).

How can I do this? Any suggestion will be very-very helpful and as soon as possible!

Thanks.


XSLT 1.0 and XPath 1.0 don't have anything close enough to "array of doubles".

In XSLT such an array can be simulated by a node-set of elements with a single text-node child (somple content in XSD terminology), such as this:

<num>1.2345</num>
<num>2.2345</num>
<num>3.2345</num>
<num>4.2345</num>
<num>-.2345</num>

Such a node-set can be passed as external parameter by the invoker of the transformation and the way this is done depends on the concrete XSLT processor. For example, the way to pass parameters to XslCompiledTransform.Transform() are defined here.

If the above node-set has been passed as the value of the globally defined xsl:param named pDoubles, then

$pDoubles[$k] selects the $k-th num element in the node-set and it's text-node child can be used implicitly in other expressions. For example:

$pDoubles[1] + $pDoubles[2]

evaluates to

3.469

In XPath 2.0 (and thus in XSLT 2.0) there is a data-type that is much closer to an array of values -- the sequence data-type.

The closest to array of doubles in XPath 2.0 is a sequence of doubles (xs:double). Such sequence can be passed as an external parameter to an XSLT 2.0 transformation and again the details how to do this are vendor-specific. For example how to do this for Saxon, look here.

Do note: Node-sets in XPath 1.0 and sequences in XPath 2.0 only simulate arrays -- they are not arrays and one of the most important differences is that while an array access is extremely fast (O(1)), the access to an arbitrary node /item of a node-set/sequence can be O(N).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜