2011-10-18 3 views
1

내가 할 수있는 경우 궁금 어떻게 내가 내 XSLT 템플릿 내부 코드를 포함 할 수 있습니다 ... 내가 함수, 변수 등을 추가 할, 내가 <xsl:choose>를 사용할 수 있지만 그건 내 요구를 충족하지 않습니다 알고 ...XSLT 템플릿 안에 일반 PHP 코드가 있습니까?

<?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> 

희망자 누구든지 도움을!

+0

PHP 스크립트에서 xslt를 출력으로 생성 할 수 있습니다. 하지만 템플릿의 일부를 평가하기 위해 PHP에서 xslt 템플릿 호출을 할 수 있다고 생각하지 않습니다. –

+0

http://www.php.net/manual/en/xsltprocessor.registerphpfunctions.php 및 http://php.net/manual/en/function.stream-wrapper-register.php도 참조하십시오. 'myvar : // variablename'과 같은 XML/XSLT에서도 사용할 수 있습니다. – hakre

+0

아직 답을 수락하지 않았습니다. 답안에서 찾고있는 것을 명확하게 설명하고 주어진 답이 왜 당신을 만족시키지 못하게 할 수 있습니까? – Gordon

답변

0

아니요, 좋지 않을 수 있습니다. 확장 함수를 작성하는 방법 인 외부 네임 스페이스의 코드를 포함 할 수는 있지만 PHP에서 수행 할 수 없다고 생각합니다. 라이브러리를로드해야하므로 일반적으로 미리 컴파일 된 언어로되어 있습니다.

달성해야 할 항목은 무엇입니까? XSL을 사용하면 XSL을 사용하여 성취 할 수없는 부분이 많지 않습니다. 예와 같이 사소한 문제에 문제가 없을 것입니다.