このJavaプログラムでは、ブール値を出力文字列にマップするために、(trueの場合は「*」、falseの場合は空文字列)を使用します。XSLT 1.0 3進数の場合のイディオムif?
public class ternary {
public static void main(String[] args) {
boolean flags[]={true,false,true};
for (boolean f : flags) {
System.out.println(f?"*":"");
}
}
}
出力は*、[空]、*です。
は、私のような、何かを入力XML文書を持っている:
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="change.xsl"?>
<root>
<change flag="true"/>
<change flag="false"/>
<change flag="true"/>
</root>
そして、私が '*' に真の '' に偽マッピングし、次のXSLTテンプレートを持っている(それが動作します):
<xsl:template match="change">
<xsl:variable name="flag" select="translate(substring(@flag,1,1),'tf','*')"/>
<xsl:value-of select="$flag"/>
</xsl:template>
もっと簡潔なバージョンがありますか?
a)文字列 'true | false'からブール値true | falseを自動的に取得できますか? b)ブール値true | falseを '*'、 ''にマップする(xpath?)構文はありますか?
似たような質問:http://stackoverflow.com/questions/971067/is-there-an-if-then-else-statement-in-xpath – Vadzim