dsw7547 2014-11-19 07:30
浏览 222
已采纳

获取xsl中的当前时间戳并将其传递给xml属性

My project is on php. And i need to Create cXML file using XSL template.

I am very new to XSL and so far i have googled and creates a XSL template which outputs cXML, My code is below.

<?xml version="1.0" encoding="ISO-8859-1"?>
<files>
<file filename="Order_%Y%%m%%d%%h%%i%%s%.xml">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="orders/order">
<xsl:variable name="created_at_timestamp" select="created_at_timestamp" />
<cXML lang="en-US" payloadID="{created_at_timestamp}" timestamp="">
<Header><From><Credential domain="NetworkID"><Identity>Enterprises</Identity></Credential></From>
<To><Credential domain="NetworkID"><Identity>xxx</Identity></Credential></To>
<Sender><Credential domain="NetworkID"><Identity>xxx Enterprises</Identity>
</Credential><UserAgent>Enterprises</UserAgent></Sender></Header>
</cXML>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
</file>
</files>

Now i need to know how to output the current timestamp in the cXML attribute timestamp, to be specific.

<cXML lang="en-US" payloadID="{created_at_timestamp}" timestamp="TIME_STAMP_HERE">

I tried many methods by googling, everything outputs only the plain text if i use it in "". For EX: if i use a function current-dateTime() it outputs like this.

<cXML lang="en-US" payloadID="{created_at_timestamp}" timestamp="current-dateTime()">

can anyone please help me to output the current timestamp inside my cXML attribute ? other parameters are working good.

EDIT Expected output is <cXML lang="en-US" payloadID="xxx" timestamp="2014-11-07T12:00:13-04:00">

Thanks

  • 写回答

1条回答 默认 最新

  • douwei4370 2014-11-19 07:41
    关注

    There is no current-dateTime() function in XSLT 1.0, which is what I believe PHP is using. Either pass the current datetime as a parameter to the stylesheet at runtime, or use the EXSLT date:date-time() extension function, which the libxslt processor supports:

    <cXML lang="en-US" payloadID="xxx" timestamp="{date:date-time()}">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效