如何使用XSLT在日期和平铺之间插入大写的T?
无法进行XSLT转换,我正在尝试在下面的XML文件中的startdate中添加/插入日期和时间之间的大写t如何使用XSLT在日期和平铺之间插入大写的T?,xslt,Xslt,无法进行XSLT转换,我正在尝试在下面的XML文件中的startdate中添加/插入日期和时间之间的大写t <?xml version="1.0"?> <callinfo> <startdate>2014-04-25 12:18:19</startdate> <duration>20</duration> <local>xxxxxxxxxxx</local> <remote>xxxxxxx
<?xml version="1.0"?>
<callinfo>
<startdate>2014-04-25 12:18:19</startdate>
<duration>20</duration>
<local>xxxxxxxxxxx</local>
<remote>xxxxxxxxxxx</remote>
<local_name></local_name>
<remote_name></remote_name>
<direction>0</direction>
<data></data>
<id>20140425_121819_x0003</id>
<recording>20140425_121819_x0003.wav</recording>
<location>//recordit_server/mobilkald/20140425_121819_x0003.wav</location>
<errormsg></errormsg>
</callinfo>
下面是我尝试使用的XSLT脚本
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:template match="/">
<Call xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Data>
<time_offset>
<xsl:number value="0"/>
</time_offset>
<audio><audio_segement>
<channel_id>0</channel_id>
<recording_order>1</recording_order>
<audio_url>
<xsl:value-of select="callinfo/location"/>
</audio_url>
<xsl:apply-templates select="callinfo/startdate"/>
<xsl:apply-templates select="StartTime"/>
<Duration>
<xsl:value-of select="callinfo/duration"/>
</Duration>
</audio_segement>
</audio>
<direction>
<xsl:value-of select="callinfo/direction"/>
</direction>
<ani>
<xsl:value-of select="callinfo/local"/>
</ani>
<dnis>
<xsl:value-of select="callinfo/remote"/>
</dnis>
<unique_identifier>
<xsl:value-of select="callinfo/startdate"/>
</unique_identifier>
</Data>
</Call>
</xsl:template>
<xsl:template match="callinfo/startdate">
<StartTime>
<xsl:variable name="startTimeSize" select = "string-length(.)"/>
<xsl:if test="$startTimeSize = 19">
<xsl:value-of select="."/>.00+00:00
</xsl:if>
<xsl:if test="$startTimeSize = 33">
<xsl:value-of select="substring(.,0,24)"/>
<xsl:value-of select="substring(.,28,7)"/>
</xsl:if>
<xsl:if test="$startTimeSize != 33 and $startTimeSize != 19">
<xsl:value-of select="."/>
</xsl:if>
</StartTime>
</xsl:template>
</xsl:stylesheet>
非常感谢您的帮助。尝试将您的callinfo/startdate模板更改为:
<xsl:template match="callinfo/startdate">
<StartTime>
<xsl:variable name="StartTime">
<xsl:value-of select="concat(substring-before(., ' '), 'T', substring-after(., ' '))"/>
</xsl:variable>
<xsl:variable name="startTimeSize" select = "string-length(.)"/>
<xsl:if test="$startTimeSize = 19">
<xsl:value-of select="$StartTime"/>.00+00:00
</xsl:if>
<xsl:if test="$startTimeSize = 33">
<xsl:value-of select="substring($StartTime,0,24)"/>
<xsl:value-of select="substring($StartTime,28,7)"/>
</xsl:if>
<xsl:if test="$startTimeSize != 33 and $startTimeSize != 19">
<xsl:value-of select="$StartTime"/>
</xsl:if>
</StartTime>
</xsl:template>
起始日期是否始终采用这种格式YYYY-MM-DD HH:MM:SS?如果是,测试字符串长度的目的是什么?如果不是,还有哪些其他格式是可能的?xsl:value作为xsl:variable的子级是不好的样式。这里更简单。