this is not my code. but it similer to what i want thats why i am using it here. i got this from here
<xsl:template match="/">
<xsl:apply-templates select="event/details">
<xsl:with-param name="title" select="event/title"/> <!-- pass param "title" to matching templates -->
</xsl:apply-templates>
</xsl:template>
<xsl:template match="details">
<xsl:param name="title"/> <!-- this template takes parameter "title" -->
Title: <xsl:value-of select="$title"/><br/>
Timestamp: <xsl:value-of select="java:DateUtil.getDate(number(timestamp))"/><br/>
Description: <xsl:value-of select="description"/><br/>
</xsl:template>
My issue is can i have above match template “details” with parameter and one without parameter? sorry for my english..let me know if i dont make sense i will try my best to reword this. thank you in advanced.
EDIT : here is what i want.
template 1 - with parameter:
<xsl:template match="details">
<xsl:param name="title"/> <!-- this template takes parameter "title" -->
Title: <xsl:value-of select="$title"/><br/>
Timestamp: <xsl:value-of select="java:DateUtil.getDate(number(timestamp))"/><br/>
Description: <xsl:value-of select="description"/><br/>
</xsl:template>
template 2 - without parameter:
<xsl:template match="/">
<xsl:apply-templates select="event/details"/>
</xsl:template>
<xsl:template match="details">
Timestamp: <xsl:value-of select="java:DateUtil.getDate(number(timestamp))"/><br/>
Description: <xsl:value-of select="description"/><br/>
</xsl:template>
I. It is a recoverable error to have two templates with the same match pattern — in the best cases only one of these will be selected for execution.
In your specific example, you can use just the template with the parameter and slightly modify its code so that when the parameter has no value (the empty string), then no title is written.
Here is a small demonstration how this can be done:
In this transformation the template matching
detailsis invoked twice — the first time without a parameter and the second time with a$titleparameter. In both cases the template produces the wanted output:II.
xsl:functionin XSLT 2.0What you want can be achieved with
xsl:function— functions written in XSLT — this feature is available only in XSLT 2.0 (and up). It is perfectly possible to write different overloads of the same function and we have many examples of this.