2013-03-18 20:26
浏览 52


I am passing the parameter movieID in the following XSLT code

<xsl:template match="movie">
  <xsl:element name="a">
  <xsl:attribute name="href">movie_details.php?movieID=<xsl:value-of select="@movieID"/></xsl:attribute>
  <xsl:value-of select="title"/>
  <xsl:element name="br" />

I want to pass and display it on the page called movie_details.php.

This is my movie_details.php code:

$xml = new DOMDocument();

$xsl = new DOMDocument;

$proc = new XSLTProcessor();

$params = $_GET['movieID'];

echo $proc->transformToXML($xml,$params);

movie_details.xsl page contains the following parameter at the top:

<xsl:param name="movieID"/>

I get a blank page with no information displayed at all.

I am able to get it to work by using the following ColdFusion code (movie_details.cfm)

<cfset MyXmlFile = Expandpath("movies.xml")>
<cffile action="READ" variable="xmlInput"  file="#MyXmlFile#">
<cfset MyXslFile = Expandpath("movie_details.xsl")>
<cffile action="READ" variable="xslInput"  file="#MyXslFile#">

<cfset xslParam = StructNew() >
<cfset xslParam["movieID"] = "#url.movieID#" >

<cfset xmlOutput = XMLTransform(xmlInput, xslInput, xslParam )>
<!--- data is output --->
<cfcontent type="text/html" reset="yes">

However, I want to do the same with PHP.

图片转代码服务由CSDN问答提供 功能建议

我在以下XSLT代码中传递参数 movieID <前> &lt; xsl:template match =“movie”&gt; &lt; xsl:element name =“a”&gt; &lt; xsl:attribute name =“href”&gt; movie_details。 php?movieID =&lt; xsl:value-of select =“@ movieID”/&gt;&lt; / xsl:attribute&gt; &lt; xsl:value-of select =“title”/&gt; &lt; / xsl :element&gt; &lt; xsl:element name =“br”/&gt; &lt; / xsl:template&gt;

我想传递并显示它 在名为 movie_details.php 的页面上。


 $ xml = new DOMDocument(); 
 $  xml-&gt; load('movies.xml'); 
 $ xsl = new DOMDocument; 
 $ xsl-&gt; load('movie_details.xsl'); 
 $ proc = new XSLTProcessor()  ; 
 $ proc-&gt; importStyleSheet($ xsl); 
 $ params = $ _GET ['movieID']; 
echo $ proc-&gt; transformToXML($ xml,$ params); 
?  &gt; 


 &lt; xsl:param  name =“movieID”/&gt; 


我是 能够通过使用以下ColdFusion代码(movie_details.cfm)

 &lt; cfset MyXmlFile = Expandpath(“movies.xml”)&gt; 
&lt; cffile使其工作 action =“READ”variable =“xmlInput”file =“#MyXmlFile#”&gt; 
&lt; cfset MyXslFile = Expandpath(“movie_details.xsl”)&gt; 
&lt; cffile action =“READ”variable =“xslInput”file  =“#MyXslFile#”&gt; 
&lt; cfset xslParam = StructNew()&gt; 
&lt; cfset xslParam [“movieID  “] =”#url.movi​​eID#“&gt; 
&lt; cfset xmlOutput = XMLTransform(xmlInput,xslInput,xslParam)&gt; 
&lt; cfcontent类型 =“text / html”reset =“yes”&gt; 
&lt; cfoutput&gt; #xmloutput#&lt; / cfoutput&gt; 

但是,我想这样做 与PHP相同。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanchi5078 2013-03-18 20:36


    • Parameter name
    • Passing parameters to transformer

    Parameter Name

    Use $movieID (instead of @movieID):

    <xsl:param name="movieID" />
    <xsl:template match="movie">
      <xsl:element name="a">
      <xsl:attribute name="href">movie_details.php?movieID=<xsl:value-of select="$movieID"/></xsl:attribute>
      <xsl:value-of select="title"/>
      <xsl:element name="br" />

    Passing Parameters

    You will have to change your PHP code to call setParameter because transformToXML does not take additional parameters.

    $xml = new DOMDocument();
    $xsl = new DOMDocument;
    $proc = new XSLTProcessor();
    $params = $_GET['movieID'];
    $proc->setParameter('', 'movieID', $params );
    echo $proc->transformToXML( $xml );
    解决 无用
    打赏 举报

相关推荐 更多相似问题