複数のチェック条件があり、特定の条件に基づいて出力要素がコピーされるxslt1.0で、以下のような冗長なコーディングを回避する方法があるかどうかを確認したかっただけです。条件が真でない場合、要素自体は出力に含まれません。私が尋ねている理由は、xslファイルに多くの要素が存在するからです。
私のxslt
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="/">
<Root>
<xsl:if test="Root/a/text() = '1'">
<first>present</first>
</xsl:if>
<xsl:if test="Root/b/text() = '1'">
<second>present</second>
</xsl:if>
<xsl:if test="Root/c/text() = '1'">
<third>present</third>
</xsl:if>
<xsl:if test="Root/d/text() = '1'">
<fourth>present</fourth>
</xsl:if>
</Root>
</xsl:template>
</xsl:stylesheet>
私の入力xml
<Root>
<a>1</a>
<b>1</b>
<c>0</c>
<d>1</d>
</Root>
私の出力
<Root>
<first>present</first>
<second>present</second>
<fourth>present</fourth>
</Root>