我正在尝试将月/日/年元素中的字符串连接成一个显示MM / DD / YYYY的值,但我找不到在xslt 1.0中执行此操作的方法,该方法将包含’/’分隔符.在xslt 2.0中使用字符串连接函数的方式.我需要在不创建新模板或使用变量/ if-logic的情况下执行此操作,因为我们尚未在课堂上“学习”.我试图连接的代码部分如下所示:
<publishedDate> <month>7</month> <day>9</day> <year>2007</year> </publishedDate>
目前我能做的最好的是:
<xsl:value-of select="concat( format-number(publishedDate/month,'##00','date'),format-number(publishedDate/day,format-number(publishedDate/year,'####','date') )"/>
哪个输出日期如下:03082014
与此同时,为了完成任务,我不得不使用一个看似如下的可怕,冗长的解决方法:
<xsl:value-of select="format-number(publishedDate/month,'date')"/>/ <xsl:value-of select="format-number(publishedDate/day,'date')" />/ <xsl:value-of select="format-number(publishedDate/year,'date')" />
解决方法
你快到了.你只需要在concat()本身中添加包含’/’的额外参数(它仍然是XSLT 1.0 – 你可以有三个以上的术语):
concat(format-number(...),'/',format-number(...),format-number(...))