アプリ版:「スタンプのみでお礼する」機能のリリースについて

まず、下記のxml、xslによりhtmlページを出力しています。

■test.xml
<?xml version="1.0" encoding="UTF-8"?>
<all>
<index file_id="a">
<product file_id="a-01">
<yoso>ああああああああああああああああ</yoso>
</product>
<product file_id="a-02">
<yoso>いいいいいいいいいいいいいいいい</yoso>
</product>
<product file_id="a-03">
<yoso>うううううううううううううううう</yoso>
</product>
<product file_id="a-04">
<yoso>ああああああああああああああああ</yoso>
</product>
<product file_id="a-05">
<yoso>いいいいいいいいいいいいいいいい</yoso>
</product>
<product file_id="a-06">
<yoso>うううううううううううううううう</yoso>
</product>
</index>
<index file_id="b">
<product file_id="b-01">
<yoso>ああああああああああああああああ</yoso>
</product>
<product file_id="b-02">
<yoso>いいいいいいいいいいいいいいいい</yoso>
</product>
<product file_id="b-03">
<yoso>うううううううううううううううう</yoso>
</product>
<product file_id="b-04">
<yoso>うううううううううううううううう</yoso>
</product>
</index>
<index file_id="c">
<product file_id="c-01">
<yoso>ああああああああああああああああ</yoso>
</product>
<product file_id="c-02">
<yoso>いいいいいいいいいいいいいいいい</yoso>
</product>
<product file_id="c-03">
<yoso>うううううううううううううううう</yoso>
</product>
</index>
</all>

■ind.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0"
xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect" extension-element-prefixes="redirect">
<xsl:output method="html" encoding="UTF-8"/>

<xsl:template match="index">
<!-- 出力ファイル名 -->
<xsl:variable name="filename" select="concat('html/',@file_id, '/index.html')"/>
<!-- 出力開始 -->
<redirect:open select="$filename"/>
<redirect:write select="$filename">
<html>
<head>
<title><xsl:value-of select="@file_id"/></title>
</head>
<body>
<h1><xsl:value-of select="@file_id"/></h1>
<xsl:apply-templates />
</body>
</html>
</redirect:write>
<redirect:close select="$filename"/>
<!-- 変換報告 -->
<xsl:value-of select="concat('『',$filename,'』変換完了')"/>
</xsl:template>

<xsl:template match="product">
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat(@file_id,'.html')" />
</xsl:attribute>
<xsl:value-of select="@file_id" />
</a><br />
</xsl:template>

</xsl:stylesheet>

■環境
・xalan-j_2_7_1
・j2sdk1.4.2_16
・windowsxp

コマンドプロンプトにより下記を実行すると

java org.apache.xalan.xslt.Process -in test.xml -xsl ind.xsl

html/a/index.html
html/b/index.html
html/c/index.html
が出力されます。

つまりは各カテゴリ(a,b,c)のproduct要素をまとめた
インデックスページが出力されます。

ここまでが現状です。
やりたいのは以下です。

上記だとproductの数にかかわらず1ページのindex.htmlに
出力されます。
test.xmlは数が少ないのでいいですが、
仮に1000個あった場合、どんでもないことになってしまうので、
ページ分割をしたいと思っています。(< 1 2 3 4 > みたいな!)
ですが、何をどうしたらよいのか皆目見当が付きません。

1ページを10個までとしてそれ以上は次ページに出力みたいなことはできるのでしょうか。
html/a/index.html
html/a/index2.html
html/a/index3.htmlみたいにです。。。


上記のxslだとmatchするtemplates(index)は3つだけなので、
xalanが書き出すのは3ぺーじだけです。
この書き出す回数をたとえばcount(product div 10)とかにできれば、
なにかみえてきそうなきもするんですが、、、、

長々と申し訳ありませんが、
ご協力お願いします。

A 回答 (1件)

JDK 7でやろうとしたらエラーが出たし、エラーの原因を把握して動作するようにするのも面倒なのでメモだけ



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

<xsl:template match="/all">
<html>
<head>
<title>Q3861990 TestCase 1</title>
</head>
<body>
<dl>
<xsl:apply-templates select="index"/>
</dl>
</body>
</html>
</xsl:template>

<xsl:template match="index">
<xsl:apply-templates select="product" />
</xsl:template>

<xsl:template match="product">
<xsl:variable name="pos" select="floor((position() - 1) div 3)" />

<xsl:call-template name="compare">
<xsl:with-param name="pos" select="$pos" />
<xsl:with-param name="current" select="." />
<xsl:with-param name="nodes" select="../product[floor((position() - 1) div 3) = $pos]" />
</xsl:call-template>
</xsl:template>

<xsl:template name="compare">
<xsl:param name="pos"/>
<xsl:param name="current" />
<xsl:param name="nodes" />
<xsl:if test="count($nodes[1]|$current) = count($current)">
<!-- 実際はここら辺にredirect:open要素やredirect:write要素の開始タグ・・ -->
<dt><xsl:value-of select="concat($current/../@file_id,string($pos))" /></dt>
<xsl:apply-templates select="$nodes/yoso" />
<!-- 実際はここら辺にredirect:open要素やredirect:write要素の終了タグ・・ -->
</xsl:if>
</xsl:template>

<xsl:template match="yoso">
<dd><xsl:value-of select="../@file_id" />:<xsl:value-of select="text()" /></dd>
</xsl:template>


</xsl:stylesheet>

出力結果

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Q3861990</title>
</head>
<body>
<dl>
<dt>a0</dt>
<dd>a-01:ああああああああああああああああ</dd>
<dd>a-02:いいいいいいいいいいいいいいいい</dd>
<dd>a-03:うううううううううううううううう</dd>
<dt>a1</dt>
<dd>a-04:ああああああああああああああああ</dd>
<dd>a-05:いいいいいいいいいいいいいいいい</dd>
<dd>a-06:うううううううううううううううう</dd>
<dt>b0</dt>
<dd>b-01:ああああああああああああああああ</dd>
<dd>b-02:いいいいいいいいいいいいいいいい</dd>
<dd>b-03:うううううううううううううううう</dd>
<dt>b1</dt>
<dd>b-04:うううううううううううううううう</dd>
<dt>c0</dt>
<dd>c-01:ああああああああああああああああ</dd>
<dd>c-02:いいいいいいいいいいいいいいいい</dd>
<dd>c-03:うううううううううううううううう</dd>
</dl>
</body>
</html>

============================================
教えてgooの仕様で,URIっぽい文字列の前後にXMLに存在できない空白文字を埋め込まれることが多い。動作しないことがよくあるのでテキストエディタで適宜編集してから使用すること。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!