プロが教えるわが家の防犯対策術!

こういったXMLファイルがあり、
XSLにて変換をしたいと思っています。

<success>
<table>
<list>
<row>
<value>value1</value>
<value>value2</value>
<value>2</value>
<value>10</value>
<value>20</value>
</row>




</list>
</table>
</success>

上の例にある、
<value>20</value>
valueの5番目が20以上のときだけ
色を変更して表示したいと思っています。

xslで
<xsl:for-each select="value">
<xsl:if test="value[5]&gt;= 20">
<xsl:attribute name="bgcolor">255,50,50</xsl:attribute>
<xsl:value-of select="."/>,
</xsl:if>

としたのですが、
うまくいきません。

条件式が問題だとは思いますが、
どのような式にしたらよいのでしょうか?

A 回答 (1件)

例えば、こんな感じ


----------------------------------------------------------------
<?xml version="1.0" encoding="Shift_JIS"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="Shift_JIS" indent="yes" />
<xsl:template match="/">
<html>
<head><title>sample</title></head>
<body>
<p>
<xsl:for-each select="//table">
<table>
<xsl:for-each select="list/row">
<tr>
<xsl:for-each select="value">
<td>
<xsl:if test="position()=5 and .&gt;=20">
<xsl:attribute name="bgcolor">#FF3232</xsl:attribute>
</xsl:if>
<xsl:value-of select="."/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:for-each>
</p>
</body></html>
</xsl:template>
</xsl:stylesheet>
    • good
    • 0

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