tags:

views:

37

answers:

2

I have this XSL file:


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

There is a C# function define in CDATA section. Does php support something similar?

A: 

It appears that you cannot do exactly what you want, hoever, this may be of some help Calling PHP Functions from XSL. I am not sure if this is what you were looking for, but does contain some good information. As far as the actual defining of a function, well given that it uses Micro$oft's schema, I am sure this functionality was written up by Micro$oft which is why you can do it with C#.

Brad F Jacobs
premiso, I read that article and it was useful but not entirely what I'm looking for. In that file the C# script is located in the CDATA part of the xsl file, this means that I can define a function that modifies the xsl data in the xsl file itself. In php I did not found a way to do this. I have to know before I parse the xsl file what data I need to modify and create a function in the php script (not xsl file) that will modify my data. Another way to put it: I can use php functions in xsl but they need to be registered first. And I could not find a way to do this from xsl file.
negatif