Masaatoshi Ito の備忘録

主にザウルス(SL-C3100)に関する備忘録を書いています。更新停滞中&書く内容迷走中…。

ZauCashのxslファイル

2010年12月02日 22時52分55秒 | Zaurus
私は、Zaurusで家計簿を付けるのに、以前はHancomSheetを使用していたのですが、最近(とは言っても半年ぐらい前から)ZauCashを使用させていただいています。
かなり時間が経ってしまっているため、詳しいことを忘れてしまいましたが、PCのFirefoxなどで家計簿のデータのxmlを開くとき、zaucash.xslを用意しておくと見やすく表示させることができます。
その機能を使用して、集計等をできる機能を実現していたのですが、久しぶりにブログのネタ&備忘録として記載しておきます。
以下が私が使用しているzaucash.xslファイルです。

zaucash.xsl
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- ルート要素 -->
<xsl:template match="/">
<html>
<head>
<title>ZauCashデータ</title>
</head>
<body text="#000000" bgcolor="#ffffff">
<h1>ZauCashデータ</h1>
<xsl:apply-templates mode="table"/>
<p></p>
<xsl:apply-templates mode="kindof"/>
<p></p>
<xsl:apply-templates mode="total"/>
</body>
</html>
</xsl:template>

<!-- 一覧表 -->
<xsl:template match="zaucash" mode="table">
<table border="1" cellpadding="4" cellspacing="0">
<tr bgcolor="#ccffff">
<th>日付</th>
<th><font color="gold">■</font>収入</th>
<th><font color="blue">■</font>支出</th>
<th>費目</th>
<th>メモ</th>
</tr>
<xsl:for-each select="record">
<xsl:sort select="@date" order="ascending"/>
<tr bgcolor="#ffffcc">
<td><xsl:value-of select="substring-before(@date,' ')"/></td>
<xsl:if test="@type='収入'">
<td align="right">
<xsl:value-of select="format-number(@money, '###,##0')"/>
</td>
<td align="right">-</td>
</xsl:if>
<xsl:if test="@type='支出'">
<td align="right">-</td>
<td align="right">
<xsl:value-of select="format-number(@money, '###,##0')"/>
</td>
</xsl:if>
<td><xsl:value-of select="@category"/></td>
<td><xsl:value-of select="@memo"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>


<!-- 項目別 -->
<xsl:template match="zaucash" mode="kindof">
<table border="1" cellpadding="4" cellspacing="0">
<tr bgcolor="#ccffff">
<th>種別</th>
<th>費目</th>
<th>合計</th>
</tr>
<xsl:for-each select="record">
<xsl:sort select="@type"/>
<xsl:sort select="@category"/>
<xsl:variable name="v1" select="@type" />
<xsl:variable name="v2" select="@category" />
<!-- 自分よりも前に同じノードがあった場合は集計済みなので無視 -->
<xsl:if test="count(preceding-sibling::record[@type=$v1][@category=$v2]) = '0'">
<!-- 自分よりも後ろにあるノードの集計 -->
<tr bgcolor="#ffffcc">
<xsl:if test="@type='収入'">
<td><font color="gold">■</font><xsl:value-of select="@type"/></td>
</xsl:if>
<xsl:if test="@type='支出'">
<td><font color="blue">■</font><xsl:value-of select="@type"/></td>
</xsl:if>
<td><xsl:value-of select="@category"/></td>
<td align="right"><xsl:value-of select="format-number(sum(following-sibling::record[@type=$v1][@category=$v2]/@money)+@money, '###,##0')"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</xsl:template>

<!-- 合計表 -->
<xsl:template match="zaucash" mode="total">
<xsl:variable name="incomeTotal">
<xsl:choose>
<xsl:when test="record/@money[../@type='収入']">
<xsl:value-of select="sum(record/@money[../@type='収入'])"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="expendTotal">
<xsl:choose>
<xsl:when test="record/@money[../@type='支出']">
<xsl:value-of select="sum(record/@money[../@type='支出'])"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<table border="1" cellpadding="4" cellspacing="0">
<tr bgcolor="#ccffff">
<th><font color="gold">■</font>収入</th>
<th><font color="blue">■</font>支出</th>
<th>残金</th>
</tr>
<tr bgcolor="#ffffcc">
<td align="right"><xsl:value-of select="format-number($incomeTotal, '###,##0')"/></td>
<td align="right"><xsl:value-of select="format-number($expendTotal, '###,##0')"/></td>
<td align="right"><xsl:value-of select="format-number($incomeTotal - $expendTotal, '###,##0')"/></td>
</tr>
</table>
</xsl:template>

</xsl:stylesheet>


コメント    この記事についてブログを書く
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする
« SHARP純正Qtopia環境のタスク... | トップ | UIViewControllerのテンプレート »
最新の画像もっと見る

コメントを投稿

Zaurus」カテゴリの最新記事