Re: [xsl] Help XSL Transformation of Data

Subject: Re: [xsl] Help XSL Transformation of Data
From: Rajesh Jain <rjain15@xxxxxxxxx>
Date: Mon, 28 Sep 2009 10:25:08 -0700 (PDT)
Hi Martin

Here is the complete XSL stylesheet. 

------------------------------------------------------------------------Start-----------------------------------------------------------------------------------

<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


<!-- ================================================================== -->
<!-- ==== G L O B A L   P A R A M E T E R S =========================== -->
<!-- ================================================================== -->

<xsl:param name="skin.images" />
<xsl:param name="webapp" />


<!-- ================================================================== -->
<!-- ==== TEMPLATE: chart-data-xml ==================================== -->
<!-- ================================================================== -->
<xsl:template name="chart-data-xml">


  <xsl:variable name="color">
    <xsl:choose>
     <xsl:when test="/page/HttpRequest/Parameters/@Color!=''"><xsl:value-of select="/page/HttpRequest/Parameters/@Color"/></xsl:when>
     <xsl:otherwise>5555ff</xsl:otherwise>
    </xsl:choose>
   </xsl:variable>

  <xsl:variable name="skip" select="count(Chart-Data/Root/Item[position()=1]/Statistics/Item) div 4"/>
  <xsl:variable name="chartids">
    <xsl:for-each select="Chart-Data/Root/Item">
      <xsl:value-of select="@ID"/><xsl:text>,</xsl:text>
    </xsl:for-each>
  </xsl:variable>



  <!-- ================================================================== -->
  <!-- Chart Data ======================================================= -->
  <!-- ================================================================== -->
    <xsl:output indent="yes"/>
  <xsl:apply-templates select="Chart-Data"/> 

  <xsl:key name="k1" match="Metrics/*" use="local-name()"/>
  
  <xsl:template match="Chart-Data">
    <chart_data>
<!--  Category (X axis) date row -->
<row>
  <null/>

  <xsl:for-each select="Root/Item[position()=1]/Statistics/Item">
<string><xsl:value-of select="@StartRawDateAndTime"/></string>
  </xsl:for-each>
  
</row>
      <xsl:for-each select="Root/Item/Statistics/Item[1]/Metrics/*">
        <row>
          <string><xsl:value-of select="local-name()"/></string>
          <xsl:for-each select="key('k1', local-name())">
            <number><xsl:value-of select="number(@TotalValue)"/></number>
          </xsl:for-each>
        </row>
      </xsl:for-each>
    </chart_data>
  </xsl:template>
  
   
   


  <!-- ==================================================================  -->
  <!-- Chart "Options" (everything EXCEPT chart_data and chart_value_text) -->
  <!-- ==================================================================  -->

  
  <axis_value separator='' 
            font='arial' 
            bold='false' 
            size='11' 
            color='888888'  
            />
  <axis_category font='arial' size='12' color='888888' alpha='75' orientation='horizontal' />    
  <chart_rect x='30' y='30' width='350' height='450' positive_color='ffffff' positive_alpha='50' negative_color='ff0000' negative_alpha='10' />
  <chart_type>Line</chart_type>
  <chart_pref line_thickness='5' point_shape='circle' fill_shape='true' />
  <chart_value color='000000' alpha='90' font='arial' bold='false' size='8' position='inside' prefix='' suffix='' decimals='0' separator='' as_percentage='false' />
  <legend_label layout='horizontal' bullet='circle' font='arial' bold='true' size='10' color='000000' alpha='85' />
   <legend_rect x='5'
                y='5'
                width='390' 
                height='10' 
                margin='5'
                fill_color='ffffff'
                fill_alpha='100'/>
<series_color>
<color>88dd11</color>
<color>ff8811</color>
<color>7744dd</color>
</series_color>
<series_explode>
<number>20</number>
</series_explode>
 

</xsl:template>

</xsl:stylesheet>

-----------------------------------------------------------------------------------------------End------------------------------------------------------------------------------------------------------------------------------






----- Original Message ----
From: Martin Honnen <Martin.Honnen@xxxxxx>
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Sent: Monday, September 28, 2009 11:31:56 AM
Subject: Re: [xsl] Help XSL Transformation of Data

Rajesh Jain wrote:

> I am using the code snippet you provided, along with the row to output the time. But this doesn't seem to work. The only thing I changed was to remove the template definition and added Chart-Data before Root. 
> I get an error XML Parsing Error: no element found
> 
> I am complete newbie, so please let me know if I have to use template definition and how to use it. 

We need to see the complete code of the stylesheet you use, if the XML parsing error occurs in that stylesheet.

If the code below is your complete stylesheet then you have certainly removed essential elements like the xsl:stylesheet element and of course also the xsl:template.

>   <xsl:key name="k1" match="Metrics/*" use="local-name()"/>
> 
> 
>     <chart_data>
> <!--  Category (X axis) date row -->
> <row>
>   <null/>
> 
>   <xsl:for-each select="Chart-Data/Root/Item[position()=1]/Statistics/Item">
> <string><xsl:value-of select="@StartRawDateAndTime"/></string>
>   </xsl:for-each>
>   </row>
>       <xsl:for-each select="Chart-Data/Root/Item/Statistics/Item[1]/Metrics/*">
>         <row>
>           <string><xsl:value-of select="local-name()"/></string>
>           <xsl:for-each select="key('k1', local-name())">
>             <number><xsl:value-of select="number(@TotalValue)"/></number>
>           </xsl:for-each>
>         </row>
>       </xsl:for-each>
>     </chart_data>



-- 
    Martin Honnen
    http://msmvps.com/blogs/martin_honnen/

Current Thread