xsl if if with text或image [英] xsl if condition with text or image
本文介绍了xsl if if with text或image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如果文本匹配,如何用图像替换字符串 AUD
。我有这个xsl代码,不知道如何使用if条件,因为我是xsl编码的新手。
I'm wondering how to replace a string say AUD
with image if the text matches. I have this xsl code and not sure how to use if condition since I'm new to xsl coding.
<xsl:template match="/">
<table class="headingstable">
<tr>
<th class="headingstop">Title</th>
<th class="headingstop">Country</th>
<th class="headingstop">Date</th>
</tr>
<xsl:for-each select="weeklyevents/event">
<tr>
<td class="headingsmid"><xsl:value-of select="title"/></td>
<td class="headingsmid"><xsl:value-of select="country"/></td>
<td class="headingsmid"><xsl:value-of select="date"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
国家/地区选择可以是显示结果中的四个之一:USA,AUS,UK和JP。所以我想创建一个IF条件 if string = UK then < img src =../ uk.jpg/>
The country select can be one of the four in display results: USA, AUS, UK and JP. so I want to create an IF condition " if string = UK then <img src="../uk.jpg" />
我不知道该怎么做,但尝试了很多次这样的事情:
I'm not sure how to do that, but tried many times like this:
<xsl:template match="country[. = 'UK']">
<img src="../uk.jpg" />
</xsl:template>
我该怎么做?
更新#1,这是我的xml代码:
<?xml version="1.0" encoding="utf-8"?>
<weeklyevents>
<event>
<title>AIG Services Index</title>
<country>AUD</country>
<date><![CDATA[05-04-2014]]></date>
</event>
<event>
<title>Bank Holiday</title>
<country>JPY</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>MI Inflation Gauge m/m</title>
<country>AUD</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>ANZ Job Advertisements m/m</title>
<country>AUD</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>Building Approvals m/m</title>
<country>AUD</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>HSBC Final Manufacturing PMI</title>
<country>CNY</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>Bank Holiday</title>
<country>GBP</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>Sentix Investor Confidence</title>
<country>EUR</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>EU Economic Forecasts</title>
<country>EUR</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>PPI m/m</title>
<country>EUR</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>Eurogroup Meetings</title>
<country>EUR</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>Final Services PMI</title>
<country>USD</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>ISM Non-Manufacturing PMI</title>
<country>USD</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>Loan Officer Survey</title>
<country>USD</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>Bank Holiday</title>
<country>JPY</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>Trade Balance</title>
<country>AUD</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>Cash Rate</title>
<country>AUD</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>RBA Rate Statement</title>
<country>AUD</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>Spanish Unemployment Change</title>
<country>EUR</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>Spanish Services PMI</title>
<country>EUR</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>Italian Services PMI</title>
<country>EUR</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>Final Services PMI</title>
<country>EUR</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>Services PMI</title>
<country>GBP</country>
<date><![CDATA[05-06-2014]]></date>
</event>
</weeklyevents>
推荐答案
您可以更改
<xsl:value-of select="country"/>
by
<xsl:choose>
<xsl:when test="country = 'USA'">
<img src="../usa.jpg" />
</xsl:when>
<xsl:when test="country = 'UK'">
<img src="../uk.jpg" />
</xsl:when>
<xsl:otherwise>
...
</xsl:otherwise>
</xsl:choose>
这篇关于xsl if if with text或image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文