Re: [xsl] How to multiply 2 sequences ?

Subject: Re: [xsl] How to multiply 2 sequences ?
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Wed, 7 Nov 2007 06:00:02 -0800
It seems that you are trying to obtain the scalar product of two vectors:

X = {x1, x2, ... , xn}

Y = {y1, y2, ... , yn}

X.Y = x1.y1 + x2.y2 + ... + xn.yn


If this is the case, have a look at my 2007 Extreme Markup Languages
presentation on FXSL 2, where this is one of the examples:

  http://www.idealliance.org/papers/extreme/proceedings/xslfo-pdf/2006/Novatchev01/EML2006Novatchev01.pdf

In particular, the following XPath expression calculates the scalar
product of two vectors $vect1 and $vect2:

          f:sum(f:zipWith(f:mult(), $vect1, $vect2)) (: Scalar product
of two vectors :)


-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play




On Nov 7, 2007 2:18 AM, TEICHERT, Peter <Peter.TEICHERT@xxxxxxxxxx> wrote:
> Hello XSLT users,
>
> I am developing an XML, XSLT 2.0 based food database.
> I am trying to extract and process the XML data but until now with limited success.
>
> The database has the following xml schema:
>
> some of the single food ingredients ( extracted via attribute id )
>
>  <xs:element name="NAME" type="xs:normalizedString">
>    <xs:annotation xml:lang="de">
>      <xs:documentation>Bezeichnung des Lebensmittels</xs:documentation>
>    </xs:annotation>
>  </xs:element>
>
>  <xs:element name="GCAL" type="xs:nonNegativeInteger">
>    <xs:annotation xml:lang="de">
>      <xs:documentation>Energie, kcal/100g</xs:documentation>
>    </xs:annotation>
>  </xs:element>
>
> all single food ingredients collected in food element "ing" having attribute id
>
> The following issues need to be solved :
>
> 1. extraction of single food ingredients
>
> <xsl:template match="/">
>
>  <xsl:variable name="input_bls" as="item()*">
>    <xsl:sequence select="('B100000', 'B105100', 'B106311')"/>
>  </xsl:variable>
>
>  <xsl:variable name="input_amt" as="item()*">
>    <xsl:sequence select="(100, 50, 10)"/>
>  </xsl:variable>
>
>  <xsl:apply-templates select="in:ingredient/in:ing[@in:id=$input_bls]"/>
> </xsl:template>
>
> this works
>
> 2. multiplication with weight factor variable $input_amt
>
> <xsl:template match="in:ingredient/in:ing">
>  <xsl:param name="input_amt">0</xsl:param>
>  <xsl:variable name="GCAL" select="in:GCAL * $input_amt"/>
> </xsl:template>
>
> this works with the same weight factor for every food element,
> but the weight factors are different for every food element
>
> 3. sum of single food ingredients per food element
>
> this is also unclear because step 2 is still unclear.
>
> Can You assist me with this ?
>
> How can I multiply a node sequence with different factors ?
>
>
> best regards
>
>
> Peter Teichert
>
>
> This e-mail is intended only for the above addressee. It may contain privileged information.
> If you are not the addressee you must not copy, distribute, disclose or use any of the information in it.
> If you have received it in error please delete it and immediately notify the sender.
> Security Notice: all e-mail, sent to or from this address, may be accessed by someone other than the recipient, for system management and security reasons. This access is controlled under Regulation of security reasons.
> This access is controlled under Regulation of Investigatory Powers Act 2000, Lawful Business Practises.

Current Thread