【问题标题】:php function defined in xsl [duplicate]xsl中定义的php函数[重复]
【发布时间】:2011-03-19 14:09:15
【问题描述】:

我有这个 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是否支持类似的东西?

【问题讨论】:

    标签: php xml xslt


    【解决方案1】:

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

    【讨论】:

    • premiso,我读了那篇文章,它很有用,但并不完全是我想要的。在该文件中,C# 脚本位于 xsl 文件的 CDATA 部分,这意味着我可以定义一个函数来修改 xsl 文件本身中的 xsl 数据。在php中我没有找到一种方法来做到这一点。在解析 xsl 文件之前,我必须知道我需要修改哪些数据,并在 php 脚本(不是 xsl 文件)中创建一个函数来修改我的数据。另一种说法:我可以在 xsl 中使用 php 函数,但它们需要先注册。而且我找不到从 xsl 文件中执行此操作的方法。
    猜你喜欢
    • 2016-04-06
    • 1970-01-01
    • 2011-02-08
    • 2013-05-18
    • 2013-05-12
    • 1970-01-01
    • 1970-01-01
    • 2019-05-09
    • 1970-01-01
    相关资源
    最近更新 更多