php函数在xsl中定义

时间:2010-07-22 14:03:06

标签: php xml xslt

我有这个XSL文件:


< ?xml version="1.0" encoding="utf-8"?>

< xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl script" xmlns:script="script">

  < msxsl:script implements-prefix="script" language="C#">

< ![CDATA[

public string formatDate(string sDate)

          {
              string sRetval = "";          
              try
              {
                  System.IFormatProvider format = new System.Globalization.CultureInfo(sSourceCulture);
                  System.IFormatProvider format2 = new System.Globalization.CultureInfo(sTargetCulture);
                  DateTime dDate = DateTime.Parse(sDate, format);
                  sRetval = dDate.ToString(sFormat, format2);
              }
              catch {}
              return sRetval;
          }
    ]] >

  < / msxsl:script>


  < xsl:template match="/">


    < ?xsl:if test="count(//item) &gt; 0">
      <br />
      <div id="ForumsBox" class="NoTabBox300">
        <h2>forum</h2>
        <div class="NoTabBoxContent">

          <ul class="Article">
            <xsl:apply-templates select="//item" />
          </ul>
        </div>
      </div>

    </xsl:if>


  < /xsl:template>

  < xsl:template match="item">

    < xsl:if test="position() &lt;= 5">

      <li>

        < xsl:value-of select="script:formatDate(pubDate)" />

        < xsl:text disable-output-escaping="yes"> </xsl:text>
    ...

  < /xsl:template>


</ xsl:stylesheet>

CDATA部分中定义了C#函数。 php支持类似的东西吗?

2 个答案:

答案 0 :(得分:0)

看来你无法完全按照自己的意愿行事,不过,这可能会有所帮助Calling PHP Functions from XSL。我不确定这是否是您正在寻找的,但确实包含一些好的信息。至于函数的实际定义,考虑到它使用的是Microsoft的模式,我确信这个功能是由Microsoft编写的,这就是为什么你可以用C#来实现它。

答案 1 :(得分:0)

相关问题