Issue with accessing XSLT Param Value

Hi Experts,

I have a little problem accessing the param value provided to an xslt service.

My Initial XSLT service has the below content.

<?xml version="1.0" encoding="utf-8" ?>
<html xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0">
	<head>
		<title>Employee Details</title>
	</head>
	<body>
		<img src="./packages/Irfan/resources/icon.jpg" alt="CompanyLogo" height="42" width="42"/>
		<b>	Name </b>	 : <xsl:value-of select="*/EmployeeDetails/name"/>
		<br/>
		<b>	Email </b>	 : <xsl:value-of select="*/EmployeeDetails/email"/>
		<br/>
		<b>	Department </b>	 : <xsl:value-of select="*/EmployeeDetails/department"/>
		<br/>
	</body>
</html>

And I am passing below XML to it.

<?xml version="1.0"?>
<FinalDocument>
  <EmployeeDetails>
    <name>Irfan</name>
    <email>email.com</email>
    <department>ok</department>
  </EmployeeDetails>
</FinalDocument>

And the result is below.

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Employee Details</title>
</head>
<body>
<img width="42" height="42" alt="CompanyLogo" src="./packages/Irfan/resources/icon.jpg"><b>	Name </b>	 : Irfan<br>
<b>	Email </b>	 : email.com<br>
<b>	Department </b>	 : ok<br>
</body>
</html>

So far good, but I wanted to take the image source path from xslParamInput, so I have modified the XSLT to below.


<?xml version="1.0" encoding="utf-8" ?>
<html xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0">
<xsl:param name="pathToImage" />
	<head>
		<title>Employee Details</title>
	</head>
	<body>
		<img src="$pathToImage" alt="CompanyLogo" height="42" width="42"/>
		<b>	Name </b>	 : <xsl:value-of select="*/EmployeeDetails/name"/>
		<br/>
		<b>	Email </b>	 : <xsl:value-of select="*/EmployeeDetails/email"/>
		<br/>
		<b>	Department </b>	 : <xsl:value-of select="*/EmployeeDetails/department"/>
		<br/>
	</body>
</html>

The above xslt gives me as the output. From the encounter of xsl:param tag, nothing below it is getting processed and if I try to validate the XSLT through an online tool, then it says “Error:XSLTProcessor::transformToXml(): Unexpected XSLT element ‘param’.” error.

I even tried like below


<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0">
<html>
	<head>
		<title>Employee Details</title>
	</head>
	<body>
		<img src="./packages/Irfan/resources/icon.jpg" alt="CompanyLogo" height="42" width="42"/>
		<b>	Name </b>	 : <xsl:value-of select="*/EmployeeDetails/name"/>
		<br/>
		<b>	Email </b>	 : <xsl:value-of select="*/EmployeeDetails/email"/>
		<br/>
		<b>	Department </b>	 : <xsl:value-of select="*/EmployeeDetails/department"/>
		<br/>
	</body>
</html>
</xsl:stylesheet>

But it gave below error
Caused by: javax.xml.transform.TransformerConfigurationException: com.wm.pkg.xslt.util.LocalizedTransformerException: [XSL.0002.9002] JAXP: Error during transformation - java.lang.NullPointerException
at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:956)
at com.wm.pkg.xslt.util.TemplatesCache.addTemplate(TemplatesCache.java:188)

I have attached the screenshot of how I am passing the input to xslt service.

Appreciate if someone can figure out what the issue is and let me know how to correct the xslt to access the param from flow service.

Thank you!

Here is the xslt service, make sure to reset the cache before you run

<?xml version = &quot;1.0&quot; encoding = &quot;UTF-8&quot;?>
<xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">   
<xsl:param name="pathToImage"/>
<xsl:template match = "/"> 
    <html> 
	<head>
		<title>Employee Details</title>
	</head>
	<body>
		<img>
		<xsl:attribute name="src"><xsl:value-of select="$pathToImage"/></xsl:attribute><xsl:attribute name="alt">CompanyLogo</xsl:attribute><xsl:attribute name="height">42</xsl:attribute><xsl:attribute name="width">42</xsl:attribute></img>
		<b>	Name </b>	 : <xsl:value-of select="*/EmployeeDetails/name"/>
		<br/>
		<b>	Email </b>	 : <xsl:value-of select="*/EmployeeDetails/email"/>
		<br/>
		<b>	Department </b>	 : <xsl:value-of select="*/EmployeeDetails/department"/>
		<br/>
	</body>
    </html> 
   </xsl:template>  
</xsl:stylesheet>

Check the output results, it does have the img source path etc.,

For input xml and xslParamInput input "pathToImage"

<?xml version=&quot;1.0&quot;?>
<FinalDocument>
  <EmployeeDetails>
    <name>Irfan</name>
    <email>email.com</email>
    <department>ok</department>
  </EmployeeDetails>
</FinalDocument>

Thanks a lot Mahesh! It’s working now with your approach.

I wouldn’t have figured it out myself. Thanks for spending the time :slight_smile: