- - PR -
XSLTでの加算処理
1
投稿者 | 投稿内容 | ||||
---|---|---|---|---|---|
|
投稿日時: 2006-08-09 18:24
いつも大変お世話になっております。
XSLTで以下のようにHTMLへ変換しようとしているのですが、処理方法がわからなくなってしまって書き込みました。 HTMLの各列の幅に<width>属性を作成し、そこにXMLの<tgroup>要素<widths>属性から取った値のうち、<colname>属性番目に値するものを、表示させています。 'in 'で区切って処理する方法は、下記投稿を参考にさせていただきました。 http://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?topic=16378&forum=9 しかしHTMLで表示させたときに幅が広がってしまったので、HTMLの<table>タグの<width>属性に各列の幅の総和を表示しようと思っています。 そこで混乱してしまっています。 各幅に表示させた<width>属性の値の総和をどうやって、<table>の<width>属性へ渡したらよいのでしょうか。 どなたかお力を貸していただけませんでしょうか。 よろしくお願いいたします。 □XML <tgroup cols = "6" widths = "0.685in 0.979in 1.106in 1.106in 1.106in 1.341in"> <thead> <row> <entry colname = "1">aaa</entry> <entry colname = "2">bbb</entry> <entry colname = "3">ccc</entry> <entry colname = "4">ddd</entry> <entry colname = "5">eee</entry> <entry colname = "6">fff</entry> </row> </thead> </tgroup> □HTML <table width=" "><!--table要素にwidth属性を作成し、属性値に各幅の総和を表示させたい--> <thead> <tr> <th width="49">aaa</th> <th width="70">bbb</th> <th width="79">ccc</th> <th width="79">ddd</th> <th width="79">eee</th> <th width="96">fff</th> </tr> </thead> </table> □XSLT <xsl:template match="tgroup"> <table> <thead> <tr> <xsl:for-each select="thead/row/entry"> <th> <xsl:call-template name="widthtemplate"/> </th> </xsl:for-each> </tr> </thead> </table> </xsl:template> <xsl:template name="widthtemplate"> <xsl:attribute name="width"> <xsl:call-template name="takeout"> <xsl:with-param name="str" select="ancestor::tgroup/@widths"/> <xsl:with-param name="num" select="@colname"/> </xsl:call-template> </xsl:attribute> </xsl:template> <xsl:template name="takeout"> <xsl:param name="str"/> <xsl:param name="num"/> <xsl:variable name="kugiri" select="'in'"/> <xsl:variable name="num1" select="$num - 1"/> <xsl:variable name="car" select="substring-before($str, $kugiri)"/> <xsl:variable name="cdr" select="substring-after($str, $kugiri)"/> <xsl:choose> <xsl:when test="$num1 = 0"> <xsl:value-of select="floor($car *72)"/><!--実数計算後、表示--> </xsl:when> <xsl:otherwise> <xsl:call-template name="takeout"> <xsl:with-param name="str" select="$cdr"/> <xsl:with-param name="num" select="$num1"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> [ メッセージ編集済み 編集者: すみれ 編集日時 2006-08-09 19:25 ] | ||||
|
投稿日時: 2006-08-09 19:24
もっと簡単なやり方あるのかな? | ||||
|
投稿日時: 2006-08-10 12:37
その他の方法
OFFICEのWeb形式で保存のhtmlのように、 width を指定するための、空でhiddenなrowを 末尾に立て その中に td を並べる。 幅の取り出しは 再帰になるのは、同じです [ メッセージ編集済み 編集者: MMX 編集日時 2006-08-10 13:04 ] | ||||
|
投稿日時: 2006-08-10 16:23
未記入さん、MMXさん、ご返答ありがとうございます。
再帰処理と変数処理が混ざって整理がつかずにいました。 現状として、XSLTの再帰処理が適していると思われるので、未記入さんの方法を参考にさせていただき、目的の値をとることができました。 MMXさんの方法、今後の参考にさせていただきます。 重ね重ね、ありがとうございました。 |
1