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:
<publishedDate>
<month>7</month>
<day>9</day>
<year>2007</year>
</publishedDate>
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!
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(...))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With