开发者

xsl format date (substring + concatenate ?)

开发者 https://www.devze.com 2022-12-14 08:05 出处:网络
I have the input <Date value=\"2009开发者_开发知识库1223\"/> and I want the output to be

I have the input

<Date value="2009开发者_开发知识库1223"/>

and I want the output to be

<Date>23122009</Date>

I was trying to use substring function to reformat the date

<xsl:value-of select="substring($Date,1,4)"/>

But how to concatenate the extracted year and months and day together.


Assuming whitespace isn't preserved, just put them one after the other:

<xsl:value-of select="substring($Date,7,2)"/>
<xsl:value-of select="substring($Date,5,2)"/>
<xsl:value-of select="substring($Date,1,4)"/>

If whitespace is preserved, just put them all on the line, without spaces between them.

The Xpath concatenation function will also work, but I find it less readable:

<xsl:value-of select="concat(substring($Date,7,2), substring($Date,5,2), substring($Date,1,4))"/>


<xsl:value-of select="substring(Date/@value, 7, 2)"/>
<xsl:value-of select="substring(Date/@value, 5, 2)"/>
<xsl:value-of select="substring(Date/@value, 1, 4)"/>


Take a look at the XSLT concat function. In your case it would be something like this (untested):

<xsl:value-of select="concat(substring($Date,1,4), substring($Date,7,2), substring($Date,5,2))"/>


Try this

<xsl:value-of select="concat(substring($Date,7,2),substring($Date,5,2),substring($Date,1,4))"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消