I wonder If I can and how can I include code inside my XSLT template… I know I can use <xsl:choose> but that doesn’t satisfy my needs, I want to add functions, variables etc…
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:php="http://php.net/xsl"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" indent="yes"/>
<xsl:template match="BackgroundReportPackage">
<!--- here i would like to add code like ---->
if ($dateofcharge < 7) {
return '
<xsl:for-each select="Charge">
<table class="special2" cellpadding="0">
<tr class="tr-border-bottom">
<td class="front-td-text" valign="top">Charge ID: </td>
<td class="minimalec">
<xsl:value-of select="ChargeId"/>
</td>
</tr>
<tr class="tr-border-bottom">
<td class="front-td-text" valign="top">Charge Type Classification: </td>
<td class="minimalec">
<xsl:value-of select="ChargeTypeClassification"/>
</td>
</tr>
</table>
';
} else {
do nothing
}
<!--- keep in mind that this code i've added is just for presentational purposes TO show you, how i want to use php code --->
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Hope anyone can help!
There is no real reason why you would write a template like that when XSLT can do if blocks. What you can look into is
XSLTProcessor::setParameter— Set value for a parameterto change template values and
XSLTProcessor::registerPHPFunctions— Enables the ability to use PHP functions as XSLT functionsto use PHP functions inside the template. This will probably make more sense.