I have some XML data that I want to convert to HTML with XSLT and I have mostly got it right. The problem with my XML input is that it contains inline if statements / boolean expressions that I have no idea how to handle.
<section>
<title>My Title</title>
<paragraph>
<phrase class="inline-if">if_xVariable || if_yVariable</phrase>
Show this text if if_xVariable or if_yVariable is true.
</paragraph>
<paragraph>
<phrase class="inline-if">if_xVariable && if_yVariable</phrase>
Show this text if if_xVariable and if_yVariable is true
</paragraph>
<paragraph>
Always show this text
</paragraph>
</section>
I have been thinking of adding xslt-vairables with each variable name (e.g. if_xVariable) to true/false and in some way check against them.
How would you go about to solve this problem?
Update This is what I've tried
<xsl:template match="section/paragraph">
<xsl:variable name="inlineif" select="phrase[@class='inline-if']"/>
<xsl:if test="$inlineif">
<p>
<xsl:value-of select="."/>
</p>
</xsl:if>
</xsl:template>
Since I have neither of if_xVariable
or if_yVariable
specified, the output should probably be something like
<p>
Always show this text
</p>
but instead I get the output from all of the paragraphs.
this is the code in xsl file
in tag
person.xml is as follow
you can use following
full example is at http://www.w3schools.com/xsl/xsl_if.asp
XSLT has no built-in dynamic evaluation of expressions. Possible solutions are discussed in the answer to this question.