[英]Regular PHP code inside XSLT template, is it possible?
我想知道是否可以以及如何在XSLT模板中包含代碼...我知道我可以使用<xsl:choose>
但這不能滿足我的需要,我想添加函數,變量等...
<?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>
希望任何人都能提供幫助!
當XSLT可以執行if塊時,您沒有理由編寫這樣的模板。 你可以看的是
更改模板值和
在模板內使用PHP函數。 這可能更有意義。
不,你不能那樣。 您可以包括來自外部名稱空間的代碼,這就是編寫擴展功能的方式,但是我懷疑您無法在PHP中完成擴展功能,它們通常是預編譯語言,因為您必須加載庫才能執行此操作。
您需要實現什么。 如果您全神貫注,XSL並沒有太多您無法實現的目標,當然,對於像您的示例這樣的瑣碎事情,您不會有任何問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.