Question : Default function argument with a variable

Hello,
I see that a function with a default argument like the one below doesn't work: why?
I'd like to pass the global variable $publicPath as default if no specified...

Are there solutions for this?
Thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
// a global variable
$publicPath = "/public/"

// the Function
myFunction($arg, $arg2 = $publicPath) {
...
}

// call the function
myFunction('myargument') // second argument is not specified, so $publicPath is used into the function
myFunction('myargument','/public/subfolder/') // second argument is specified, it should override the default $publicPath variable

Answer : Default function argument with a variable

Here is an XSLT code which I believe generates the output you need:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
	<xsl:key name="sh" match="SalesHeader" use="concat(SalesDate,Location,RevenueCentre)"/>
	<xsl:key name="st" match="SalesTransaction" use="concat(../SalesDate,../Location,../RevenueCentre,PLU,Description,NetSalesPrice,GrossSalesPrice)"/>
	
	<xsl:template match="/MainHeader/OrganisationHeader">
	<MainHeader xmlns="">
	    <OrganisationHeader>        
		<xsl:for-each select="SalesHeader[generate-id(.)=generate-id(key('sh',concat(SalesDate,Location,RevenueCentre)))]">
			<SalesHeader>
	            <xsl:copy-of select="SalesDate"/>
	            <xsl:copy-of select="Location"/>
	            <xsl:copy-of select="RevenueCentre"/>
	            <xsl:copy-of select="ActionIfDataExists"/>
	            <xsl:variable name="cur-header" select="concat(SalesDate,Location,RevenueCentre)"/>
				<xsl:for-each select="key('sh',$cur-header)/SalesTransaction[generate-id(.)=generate-id(key('st',concat(../SalesDate,../Location,../RevenueCentre,PLU,Description,NetSalesPrice,GrossSalesPrice)))]">
					<SalesTransaction>
					<xsl:variable name="cur-trans" select="concat(../SalesDate,../Location,../RevenueCentre,PLU,Description,NetSalesPrice,GrossSalesPrice)"/>
	                <xsl:copy-of select="PLU"/>
	                <xsl:copy-of select="Description"/>
	                <Quantity><xsl:value-of select="sum(key('st',$cur-trans)/Quantity)"/></Quantity>
	                <VAT><xsl:value-of select="format-number(sum(key('st',$cur-trans)/VAT),'#0.00')"/></VAT>
	                <TotalGrossSales><xsl:value-of select="format-number(sum(key('st',$cur-trans)/TotalGrossSales),'#0.00')"/></TotalGrossSales>
	                <xsl:copy-of select="NetSalesPrice"/>
	                <xsl:copy-of select="GrossSalesPrice"/>
	                <TotalNetSales><xsl:value-of select="sum(key('st',$cur-trans)/TotalNetSales)"/></TotalNetSales>
	                <xsl:copy-of select="CategoryCode"/>
	                <xsl:copy-of select="SaleType"/>
	                </SalesTransaction>
    			</xsl:for-each>		
			</SalesHeader>
		</xsl:for-each>
	    </OrganisationHeader>
	</MainHeader>
</xsl:template>
</xsl:stylesheet>
Random Solutions  
 
programming4us programming4us