dswqz24846 2014-10-18 00:46
浏览 55
已采纳

XSL中的睡眠功能

I think there is no direct way to do this in XSL but wanted to check with you all before writing a server-side code.

I'm working on a website to display tweets from hundreds of different accounts using twitter API. There is a large XML file containing 200+ twitter ID's and count (1-12). I have a PHP script that does OAuth and outputs JSON using the twitter API. This PHP file takes both id and count as query strings. Now twitter does have a limit to the number of requests that can be sent per 15 minutes. Since the web page is generated using XSL transformation via Saxon, I was thinking to do something like-

  <xsl:template name="all-social">

    <xsl:for-each select="/social/twitter">
      <xsl:value-of select="unparsed-text(concat('http://something/twitter.php?
    id=',@id,'&amp;count=',@count))"/> 
       <!-- or apply-templates select="document(--URL--)" -->
    </xsl:for-each> 

  </xsl:template>

This will return the JSON of tweets and I can do everything on the front-end to display it properly. But to overcome the API limit I need to add a pause or sleep inside the for-each loop like-

      <xsl:template name="all-social">

        <xsl:for-each select="/social/twitter">

           <!-- Wait for 5 seconds -->

          <xsl:value-of select="unparsed-text(concat('http://something/twitter.php?
        id=',@id,'&amp;count=',@count))"/>
        </xsl:for-each> 

      </xsl:template>

Again, I understand this is very easy to do by just using the server-side scripting, by I'm curious if there is a way to add a sleep() during XSL transformation. Any ideas/recommendation will be highly appreciated.

  • 写回答

3条回答 默认 最新

  • doude5860 2014-10-18 15:59
    关注

    I can think of two ways to do this: one is to execute the transformation periodically on the server (i.e. sleep between transformations), the other is to generate HTML code containing Javascript (or Saxon-CE) code that periodically fetches the twitter feed. We demonstrated how to do the latter in a paper at XML Prague 2013.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?