xslでhtmlのリストに変換する際、
<xsl:sort select="point" data-type="number" order="descending" />
(pointはソート対象の数字です)
を入れても、リストに反映されません。60点以上の点を取った生徒の成績の順に並び変えて表示する課題なのですが、以下の状態だと、
<xsl:sort select="point" data-type="number" order="descending" />
が無くても結果が変わりません。60点以上の条件処理は出来ています。
for-eachを使うことも考えましたが、コードが長くややこしくなるので、sortだけで解決したいです。(教科書にはfor-eachを使ってsortを書く方法も書いてありました)
<xsl:apply-templates select="students">
の部分を、
<xsl:apply-templates select="students/student">
に変えるとテーブル表示が解除される代わりにソートされます。文字だけで全てが改行無しで並んで、並びだけがソートで変わった状態です。
テーブルの順位と成績が入っているのは、これが解決した後に加えるので、無視してください。
現在の状態は下のスクショの通りです。これを降順にしたいです。
lang
1 2<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 3 <xsl:output method="html" encoding="Shift_JIS" /> 4 <xsl:template match="/"> 5 <html> 6 <xsl:apply-templates select="students"> 7 <xsl:sort select="point" data-type="number" order="descending" /> 8 </xsl:apply-templates> 9 </html> 10 </xsl:template> 11 <xsl:template match="students"> 12 <body> 13 <table border="3"> 14 <tr> 15 <th>順位</th> 16 <th>学生番号</th> 17 <th>氏名</th> 18 <th>点数</th> 19 <th>成績</th> 20 </tr> 21 <xsl:apply-templates select="student" /> 22 </table> 23 </body> 24 </xsl:template> 25 <xsl:template match="student"> 26 <xsl:if test="point >= 60"> 27 28 <tr> 29 <xsl:apply-templates select="@id" /> 30 <xsl:apply-templates select="name" /> 31 <xsl:apply-templates select="point" /> 32 </tr> 33 </xsl:if> 34 </xsl:template> 35 <xsl:template match="@id"> 36 <td> 37 <id> 38 <xsl:value-of select="." /> 39 </id> 40 </td> 41 </xsl:template> 42 <xsl:template match="name"> 43 <td> 44 <xsl:copy-of select="." /> 45 </td> 46 </xsl:template> 47 <xsl:template match="point"> 48 <td> 49 <xsl:copy-of select="." /> 50 </td> 51 </xsl:template> 52</xsl:stylesheet>
![イメージ説明]WIDTH:287
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/07/10 02:58