【问题标题】:Store variable in XSL在 XSL 中存储变量
【发布时间】:2012-06-08 22:14:23
【问题描述】:

我正在编写一个程序来从 xsl 调用 php,但我需要存储一个 xsl 变量,以便我可以将它发送到 php 函数 php:functionString()

<xsl:template match="atom:entry">

 <xsl:if test="position() &lt;= 10">
   <table border="0" width="55"  cellpadding="2" cellspacing="4" style="float:left;">
      <tr >
         <td width="55">

    <a href="?page_id=9#anchor-{ atom:id }" >
    <img id="icon">
<xsl:attribute name="src">

<xsl:value-of select="./im:image[1]"/>

</xsl:attribute>
</img></a>
</td>
</tr>

         <tr> <td width="35" style="font-family:Arial; font-size:10px; color:black; font-weight:bold;">
             <xsl:value-of select="atom:category/@label"/> </td></tr>
          <tr> <td width="35" style="font-family:Arial; font-size:10px; color:black;">   <xsl:value-of select="./im:price"/>
         </td>
     </tr>
     <tr> <td>Rating: <xsl:value-of select="php:functionString('PD::parseData','$id')" disable-output-escaping="yes"/></td>
     </tr>
     </table>
     </xsl:if>
   </xsl:template>

【问题讨论】:

  • 如果函数php:functionString() 期望它的第二个参数是一个字符串,双精度或布尔值,并且$id(你忘了给我们看!)包含这样一个值,那么很可能参数将通过 OK。您需要测试 PHP 中应该为文档节点、节点、属性或节点集使用什么类型。
  • $id 只是一个例子。我只需要正确的语法来代替 $id 并且它是 atom:id 的值,我只是不知道如何存储 id 并将其传递给 php:functionString()
  • 尼丁裤子:使用:&lt;xsl:variable name="id" select="atom:id"/&gt;。然后将其传递给函数,就像您在代码示例中所做的那样。或者,尝试:&lt;xsl:variable name="id" select="string(atom:id)"/&gt;
  • Nitin Pant:你需要读一本关于 XSLT 的好书:stackoverflow.com/a/341589/36305
  • @dimitre 我是否使用 php:functionString('PD::parseData','{$id}')php:functionString('PD::parseData','{$id}') ,它唯一传递的字符串(而不是值!) {$id} 或 $id 对应..请帮助。我正在尝试设置 iTunes iOS 应用程序 RSS 提要的样式,并使用 O'reilly 撰写的“XSLT Mastering XML Transformations”一书

标签: php xml xslt variables store


【解决方案1】:

不要使用

<xsl:value-of select="php:functionString('PD::parseData','$id')" disable-output-escaping="yes"/>

使用

<xsl:value-of select="php:functionString('PD::parseData', $id)"/>

前者作为参数传递 字符串 "$id" 而不是变量 $id

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-05
    • 2018-11-17
    • 1970-01-01
    • 1970-01-01
    • 2012-09-15
    • 2021-06-22
    • 1970-01-01
    • 2013-04-18
    相关资源
    最近更新 更多