Project

General

Profile

Часто задаваемые вопросы » RAO.xsl

Tatiana Zharkova, 04/10/2010 12:31

 
<?xml version='1.0' encoding="windows-1251"?>


<!--
Rao report template file version 1.0
24 jan 2008
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:tractt ="urn:www.tract.ru:digispot2:report-template"
xmlns:tracts ="urn:www.tract.ru:digispot2:report-script"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
version="1.0">

<tractt:environment>
<tractt:fields>
<tractt:field name="report-start-date" type="time" subtype="date" title="Дата начала отчета" format="%d %B %Y" visible="0" />
<tractt:field name="report-end-date" type="time" subtype="date" title="Дата окончания отчета" format="%d %B %Y" visible="0"/>
<tractt:field name="report-date" type="time" title="Дата отчета" subtype="date" format="%d.%m.%Y" />
</tractt:fields>

<tractt:source-template src="RAO_hdr.xml" name="ehead" />
</tractt:environment>

<msxsl:script language="JScript" implements-prefix="tracts">
<![CDATA[
var Counter = 1;
function NextCounter() {
return Counter++;
}

function TimeStr( seconds )
{
seconds = parseInt(seconds);
var h = Math.floor(( seconds ) / 3600 );
var m = Math.floor(( seconds % 3600 ) / 60 );
var s = (seconds % 60);
var ss = new String(h)
if( ss.length <2 )
ss = "0"+ ss;
var res = ss + ":";

var ss = new String(m)
if( ss.length <2 )
ss = "0"+ ss;
res = res + ss + ":";

ss = new String(s)
if( ss.length <2 )
ss = "0"+ ss;
res = "1899-12-31T"+ res + ss;
return res;
}
]]>
</msxsl:script>
<xsl:output method="xml" version='1.0' omit-xml-declaration="yes" indent="yes" />

<xsl:key name="artist_search" match="//tractt:tract-data//tractt:item" use="tractt:artist"/>
<xsl:key name="title_search" match="//tractt:tract-data//tractt:item" use="concat(tractt:artist, '=>', tractt:title)"/>

<xsl:template match="/">
<xsl:processing-instruction name="mso-application"> progid="Excel.Sheet"</xsl:processing-instruction>
<xsl:apply-templates select="//ss:Workbook" />
</xsl:template>

<!-- stubs -->
<xsl:template match="//ss:Table/@ss:ExpandedRowCount" />
<xsl:template match="//ss:Table/@ss:ExpandedColumnCount" />
<xsl:template match="//ss:Row/@ss:Index" />

<xsl:template match="//ss:Workbook">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

<xsl:template match="//ss:Styles">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
<Style ss:ID="TractLongHourTime">
<NumberFormat ss:Format="[h]:mm:ss"/>
</Style>
<Style ss:ID="TractMmSsTime">
<NumberFormat ss:Format="mm:ss"/>
</Style>
</xsl:copy>
</xsl:template>


<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

<xsl:template match="//ss:Data[starts-with(string(.),'tt:')]">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:copy />
</xsl:for-each>
<xsl:value-of select="//tractt:header/*[local-name(.)=substring-after(current(),':')]" />
</xsl:copy>
</xsl:template>
<xsl:template match="//ss:Row[string(.//ss:Data)='tp:report-list']">
<!-- <xsl:copy-of select="." /> -->
<xsl:for-each select="//tractt:report-data/tractt:item[count( . | key('artist_search',tractt:artist)[1])=1]">
<!-- один раз для артиста. Контекст=первый item c таким артистом-->
<xsl:sort select="tractt:artist" />
<xsl:variable name="songs" select="key('artist_search',tractt:artist)" />
<xsl:variable name="artsongs" select="$songs[generate-id()=generate-id(key('title_search',concat(tractt:artist, '=>', tractt:title))[1])]" />
<xsl:call-template name="songsofartist">
<xsl:with-param name="songs" select="$artsongs"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>


<xsl:template name="songsofartist">
<xsl:param name="songs"/>
<xsl:for-each select="$songs">
<!-- Вызывается один раз для уникальной пары artist-title.
текущий узел - первый item с такими artist-title. -->
<xsl:sort select="tractt:title" />
<xsl:variable name="samesongs" select="key('title_search', concat(tractt:artist, '=>', tractt:title))"/>
<Row>
<Cell><Data ss:Type="String"></Data></Cell>
<Cell><Data ss:Type="String"> <xsl:value-of select="tractt:title" /> </Data></Cell>
<Cell><Data ss:Type="String"> <xsl:value-of select="tractt:author" /> </Data></Cell>
<Cell ss:StyleID="TractMmSsTime" ss:Formula="=TIME(0,0,{number($samesongs[1]/tractt:playtime)})">
<Data ss:Type="DateTime" >1899-12-31T00:00:00</Data>
</Cell>
<Cell><Data ss:Type="Number"> <xsl:value-of select="count($samesongs)"/></Data></Cell>
<Cell ss:StyleID="TractLongHourTime" ss:Formula="=RC[-2]*RC[-1]" ><Data ss:Type="DateTime">1899-12-31T00:00:00</Data></Cell>
<Cell><Data ss:Type="String"> <xsl:text>Песня</xsl:text></Data></Cell>
<Cell><Data ss:Type="String"> <xsl:value-of select="tractt:artist" /></Data></Cell>
</Row>

<!-- <xsl:value-of select="tracts:FTime( $samesongs[1]/tractt:playtime)"/> -->
<!-- <Cell><Data ss:Type="Number"><xsl:value-of select="tracts:NextCounter()" /></Data></Cell> -->
<!-- <Cell ss:StyleID="TractTimeStyle"><Data ss:Type="DateTime"><xsl:value-of select="tracts:FTime( sum($samesongs/tractt:playtime))"/></Data></Cell> -->

</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

(3-3/13)
Add picture from clipboard (Maximum size: 742 MB)