Mostrando entradas con la etiqueta CALCULO DE TOTALES. Mostrar todas las entradas
Mostrando entradas con la etiqueta CALCULO DE TOTALES. Mostrar todas las entradas

martes, 14 de abril de 2009

Calculo de Totales sin usar la función SUM usando XSLT en Sharepoint

Objetivo:
Calcular una columna de totales, con su formateo.


Ingredientes:
Una función XSLT
La llamada a la función call-template
Un DataSet cargado y la selección correcta del conjunto por XPATH

Receta:
Hay que poner la función fuera de los tags xsl-template y así la podemos usar en el webpart
Calculo de totales en sharepoint con una función XLST

LA FUNCIÓN DE TOTALIZACIÓN
<xsl:template name="total">
<xsl:param name="seq"/>
<xsl:param name="total-so-far" select="0"/>
<xsl:choose>
<xsl:when test="$seq">
<xsl:call-template name="total">
<xsl:with-param name="seq"
select="$seq[position()!=1]"/>
<xsl:with-param name="total-so-far"
select="$total-so-far + translate($seq[1],',','.')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number($total-so-far, '#.##0;-#.##0')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


LA LLAMADA A LA FUNCIÓN
<xsl:call-template name="total">
<xsl:with-param name="seq" select="
dsQueryResponse/Rows/Row/@Total_x0020__x0028_con_x0020_IVA" />
</xsl:call-template>




FUNCIÓN DE TOTALIZACIÓN CON FORMATEO EUROPEO (ver post de formateo numérico)
<xsl:template name="total">
<xsl:param name="seq"/>
<xsl:param name="total-so-far" select="0"/>
<xsl:choose><xsl:when test="$seq">
<xsl:call-template name="total">
<xsl:with-param name="seq"select="$seq[position()!=1]"/>
<xsl:with-param name="total-so-far"select="$total-so-far + translate($seq[1],',','.')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number($total-so-far, '##0,##;-##0,##','european')"/>
</xsl:otherwise></xsl:choose>
</xsl:template>

FUNCIÓN DE TOTALIZACIÓN DE PORCENTAJES
<xsl:template name="totalPercent">
<xsl:param name="seq"/>
<xsl:param name="total-so-far" select="0"/>
<xsl:choose>
<xsl:when test="$seq">
<xsl:call-template name="totalPercent">
<xsl:with-param name="seq" select="$seq[position()!=1]"/>
<xsl:with-param name="total-so-far" select="$total-so-far + translate($seq[1],',','.')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number($total-so-far div 100, '##0,## %;-##0,## %','european')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

NOTA: 'EUROPEAN' es un formateo numerico que he definido yo mismo en el webpart y hay que declararlo, puedes ver este post anterior http://sharepointworks.blogspot.com/2009/04/formateo-europeo-de-datos-numericos-en.html

Saludos a toda la comunidad de sharepoint
http://www.robertomarcos.com/