How can one call a ColdFusion function, passing in attribute values as arguments, inside an XML transform template statement. For example, something like:
<xsl:template match="date">
<cfoutput>#DateFormat(now(), <xsl:value-of select="@format"/>)#</cfoutput>
</xsl:template>
Such that the following XML:
<date format="mm/dd/yy" />
Would be matched and transformed to the result of DateFormat(now(), "mm/dd/yy")
? Is it possible? I am able to do it with static arguments to DateFormat()
, cannot figure out how to extract a value from an attribute/node and use it as an argument. Thank you!
Update
Full version of current attempt:
<cfxml variable="xmlData">
<?xml version="1.0"?>
<date format="mm/dd/yy" />
</cfxml>
<cfxml variable="stylesheet">
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="date">
<cfoutput>#DateFormat(now(), '<xsl:value-of select="@format"/>')#</cfoutput>
</xsl:template>
</xsl:stylesheet>
</cfxml>
<cfoutput>#XmlTransform(xmlData, trim(stylesheet))#</cfoutput>
which results in the following error:
An error occured while Parsing an XML document. Element type "x2l:value-of" must be followed by either attribute specifications, ">" or "/>".