This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Multiple Element Values


> 
> My attempt at filling in the Gaps:
> ------------------------
> 
> 1:<xsl:template name="process-items">
> 2: <xsl:param name="fragmentQtyPrice"
> 3:                select="product/ref[@Qty and @Price]"/>
> 4: <xsl:if test=fragmentQtyPrice/>
> 5:   <xsl:variable name="first"
>                       select="fragmentQtyPrice[1]"/>
Following code corrected, you can't use <xsl:call-template> in an attribute,
it
has to be in the body of the xsl:variable
> 6:   <xsl:variable name="total-of-rest">
> 7:      <xsl:call-template name="process-items">
> 8:         <xsl:with-param name="fragmentQtyPrice"
> 9:                   select="fragmentQtyPrice[position()!=1]"/>
  9a      </xsl:call-template>
> 10:  </xsl:variable>
> 11:  <xsl:value-of select="$first/Qty * $first/Price + $total-of-rest"/>
> 12:</xsl:template>
> 
> 
> Subsequent Questions:
> -----------------
> 
> Line 2 and 3: Can I create an item list of qty's and price's using
> this line of code. I am concerned with the use of 'and' ?

this is correct, it contructs the set of product/ref elements that have both
a Qty and a Price attribute.
> 
> Line 5: I assume this is considering the first occurance of qty and
> price
> (or rather the top appearing values if liken to a stack-loosing each
> first instance of qty and price per loop)

Yes. Its actually the first ref element in the node-set.
> 
> Line 6: Creates a variable total-of-rest which has a recursive nested
> xsl:call-template in it's select, (hope I can do this?)

As shown, the call-template has to go in the body of the <xsl:variable>
element.
> 
> Here I have a question: when passing a value back into a function it's
> my understanding the param should be incrementing in value so that
> the recursive call will loop through the list of qty and prices. Is
> this happening here - how does position()!=1 achieve this???
> 
> Line 6: I am not sure if I have correctly setup the param to pass into
> the recursive function call?
> 
> Line 11 I am not sure at which point I can save the individual
> values calculated for qty*price into a variable so that I may finally
> display this in a html table. 

When you call the above template as 
<xsl:variable name="total">
  <xsl:call-template name="process-items"/>
</xsl:variable>

then you can reference the total as $total.

> 
> 
> Reading Explorations
> ----------------
> 
> I wondered if I might be able to use of some of this code to:
> 
> *  Return a node-set to pass to the function.
> 
>      However: is a node-set simply just a match pattern
>      on the result tree? 

An <xsl:variable> element with content (like <xsl:call-template>) constructs
a tree (XSLT calls it a result tree fragment). There are two things you can
do with this tree: flatten it to a string, or copy it to another tree
(typically the final result tree). The node-set() function adds a third
option, you can convert the tree to a node-set. In fact this node-set will
always contain a single node, the root of the tree. Doing this allows you to
walk around the tree as if it were the source document or a document loaded
using the document() function.

As it seems strange that
>      xsl would provide the sum function but not a means
>      of passing in an arguement of the right type ie. node-set?

The sum() function does indeed take a node-set as its argument, its
limitation is that it can only form
sigma(i=1..n)(number(string-value(node[i])), i.e. the sum of the numeric
values of the nodes; it cannot form the sum of some other function applied
to the nodes. This is because XSLT does not have first-class functions, you
cannot supply a function as an argument to another function.

 
> *  Make use of maths functions in java not available in xsl
> 
>                  <xsl:value-of select="math:sqrt($arg)"
>                     xmlns:math="http://java.sun.com/java.lang.Math"/>
> 
>     By the way it seems that sun have moved this library, I
>      was not able to find this http resource site?

Namespace URIs do not point to any resource, they are just conventional
names. Saxon doesn't care what URI you use to identify a Java class so long
as it ends in the full class name. I spent a lot of effort resisting the use
of the "http:" protocol name in  URIs that had nothing to do with retrieving
things via HTTP, but I lost.

> 
> 
> * I also read about NodeSet Expressions: 
> nodeset-expression1[predicate]
>    and ArithmeticExpression(Expression p1, int op, Expression p2)

that looks like a line of Saxon source code, you have been delving deeply.

Mike Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]