cancel
Showing results for 
Search instead for 
Did you mean: 

CPI XSLT - Using of header variable in XSLT

0 Kudos

hi everyone,

I am trying to use an CPI header named termdate in my XSLT mapping (in xsl file)as a parameter.

According to this blog it should be possible to do so by simply defining a parameter since XSLT parameters are automatically bound to Camel headers.

https://blogs.sap.com/2018/03/27/sap-cpi-accessing-header-and-property/

My XSLT is as below:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:hci="http://sap.com/it/" exclude-result-prefixes="hci">
 <xsl:param name= "termdate"/>
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>
 <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
 </xsl:template>

 <xsl:template match="/queryCompoundEmployeeResponse/CompoundEmployee[(person/employment_information/payrollEndDate <= '$termdate')]"/>
</xsl:stylesheet>

I am not facing any errors while running this mapping step. But the filter condition does not seem to work. (FilterCondition: PayrollEndDate lessthanorEqual to $termdate)

Please help me to use it in the right way. I am using the right syntax and right declarations ?

Best Regards, Sravan

Accepted Solutions (0)

Answers (6)

Answers (6)

shankar7891
Explorer
0 Kudos

Hi,

Try removing the single quote for the variable $termdate

Muniyappan
Active Contributor
0 Kudos

I have tried this scenario and it works fine for me with parameter.

input fle

<?xml version="1.0" encoding="UTF-8"?>
<queryCompoundEmployeeResponse
	xmlns:hci="http://sap.com/it/">
	<CompoundEmployee>
		<person>
			<employment_information>
				<payrollEndDate>01012019</payrollEndDate>
			</employment_information>
		</person>
	</CompoundEmployee>
	<CompoundEmployee>
		<person>
			<employment_information>
				<payrollEndDate>07022020</payrollEndDate>
			</employment_information>
		</person>
	</CompoundEmployee>
</queryCompoundEmployeeResponse>

xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:ns1="http://sap.com/it/" >
	
	<xsl:output omit-xml-declaration="yes" indent="yes"/>
	<xsl:strip-space elements="*"/>
	<xsl:param name= "termdate"/>
	<xsl:template match="node()|@*">
		<xsl:copy>
			<xsl:apply-templates select="node()|@*"/>
		</xsl:copy>
	</xsl:template>
  <xsl:template match="/queryCompoundEmployeeResponse/CompoundEmployee[person/employment_information/payrollEndDate[text() <= $termdate]]"/>
</xsl:stylesheet>




output

vitor_lemberck
Employee
Employee
0 Kudos

Hello Potnuru,

You will need to Start the Debug mode trace in CPI.

When you get the Value, you can check if it occurred as expected and do the changes if necessary.

Regards,

Muniyappan
Active Contributor
0 Kudos

then cay try to debug xslt and check what value you are getting when you remove static variable.

Muniyappan
Active Contributor
0 Kudos

makes sense. can you try step two? could you please paste here your input xml?

0 Kudos

I have used a static variable for Termdate to test and my xpath is working fine as expected. only problem is with accessing the header variable in my XSL

<xsl:template match="/queryCompoundEmployeeResponse/CompoundEmployee[(person/employment_information/payrollEndDate <= '$termdate')]"/>
Muniyappan
Active Contributor
0 Kudos

1.you are only declaring termdate variable and not providing any value.

<xsl:param name="termdate" slect="give your date here"/>

https://www.oreilly.com/library/view/xslt/0596000537/ch04s04.html

2. I am not sure if your second template match expression is right or wrong. once you provide value to your temdate variable and you get desired output, then ignore this step. else you could also change expression like below and try.

/queryCompoundEmployeeResponse/CompoundEmployee/person/employment_information[payrollEndDate <= '$termdate']
0 Kudos

Hi Muniyappan,

termdate is a header which I have declared in CPI iflow before my XSLT mapping.

I would like to use the same in my mapping.

I have referred to https://blogs.sap.com/2018/03/27/sap-cpi-accessing-header-and-property/

But still its not working.