Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Using concat() with a separator in XSLT 1.0

I'm trying to concatenate strings in month/date/year elements into a single value that displays MM/DD/YYYY, but I can't find a way to do it in xslt 1.0 that will include the '/' separator in the way a string-join function would in xslt 2.0. I need to do this without creating new templates or using variables/if-logic because we haven't "learned" that yet in my class. The section of code I'm trying to concatenate looks like this:


Currently the best I can do is:

<xsl:value-of select="concat(
format-number(publishedDate/month, '##00', 'date'),
format-number(publishedDate/day, '##00', 'date'),
format-number(publishedDate/year, '####', 'date')

Which outputs dates like this: 03082014

In the mean time, for the purposed of the assignment, I'm forced to use a hideous, lengthy workaround that looks like this:

<xsl:value-of select="format-number(publishedDate/month, '##00', 'date')"/>/
<xsl:value-of select="format-number(publishedDate/day, '##00', 'date')" />/
<xsl:value-of select="format-number(publishedDate/year, '####', 'date')" />

And outputs correctly (i.e. 03/08/2014). Do you guys know a way to get this output by using a a 1.0 function? Thanks!

like image 919
user3281385 Avatar asked Mar 21 '23 07:03


1 Answers

You're almost there. You just need to add extra parameters containing '/' in the concat() itself (it's still XSLT 1.0 - you can have more than three terms):

concat(format-number(...), '/', format-number(...), '/', format-number(...))
like image 150
helderdarocha Avatar answered Apr 19 '23 23:04