ProDraz
ProDraz

Reputation: 1281

Regular PHP code inside XSLT template, is it possible?

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!

Upvotes: 1

Views: 973

Answers (2)

Gordon
Gordon

Reputation: 316999

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

to change template values and

to use PHP functions inside the template. This will probably make more sense.

Upvotes: 2

Woody
Woody

Reputation: 5130

No, you can't like that. You can include code from external namespaces, which is how you would write extension functions but I suspect you wouldn't be able to do them in PHP, they are normally in pre compiled languages as you have to load libraries to do it.

What is it you need to achieve. there is not that much that you can't achieve with XSL if you put your mind to it, certainly you wouldn't have a problem with something trivial like your example

Upvotes: 0

Related Questions