<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Parth on Livecycle &#187; XPath</title>
	<atom:link href="http://blog.pandyaparth.com/category/xpath/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pandyaparth.com</link>
	<description>aka - LiveCycle Karma (Personal blog on LiveCycle, Adobe enterprise technologies and innovation)</description>
	<lastBuildDate>Mon, 05 Jul 2010 01:25:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Conditional set value using XPath</title>
		<link>http://blog.pandyaparth.com/2009/11/conditional-set-value-using-xpath/</link>
		<comments>http://blog.pandyaparth.com/2009/11/conditional-set-value-using-xpath/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 06:07:25 +0000</pubDate>
		<dc:creator>Parth Pandya</dc:creator>
				<category><![CDATA[LiveCycle Components]]></category>
		<category><![CDATA[LiveCycle ES]]></category>
		<category><![CDATA[LiveCycle ES2]]></category>
		<category><![CDATA[Workbench]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XPath]]></category>
		<category><![CDATA[Innovation]]></category>
		<category><![CDATA[XPath expression]]></category>

		<guid isPermaLink="false">http://blog.pandyaparth.com/?p=146</guid>
		<description><![CDATA[In my quest to use XPath functions &#38; expressions more efficiently in LiveCycle I managed to achieve &#8216;conditional set value&#8217; yesterday. Example scenarios: Add some text to email body if some condition is true/false. Add some text into T&#38;Cs if certain product is selected. In a generic/single Email or Set Value step you need to [...]]]></description>
			<content:encoded><![CDATA[<p>In my quest to use XPath functions &amp; expressions more efficiently in LiveCycle I managed to achieve &#8216;conditional set value&#8217; yesterday.</p>
<h3>Example scenarios:</h3>
<ul>
<li>Add some text to email body if some condition is true/false.</li>
<li>Add some text into T&amp;Cs if certain product is selected.</li>
<li>In a generic/single Email or Set Value step you need to construct a big block of text. eg. Offer letter with certain paragraphs based on few conditions.</li>
</ul>
<h3>Approach 1: The usual way (or one of the usual ways):</h3>
<p>An orchestration in Workbench with <span style="color: #ff0000;">few setValue steps</span> and<span style="color: #ff0000;"> few conditional routes</span> to add/append the desired text to existing text.</p>
<p>And these steps need to be in certain order.</p>
<h3>Approach 2: The XPath trick</h3>
<p>I used <span style="color: #0000ff;">substring()</span> and<span style="color: #0000ff;"> number()</span> function with pure <span style="color: #0000ff;">XPath expression</span> to construct conditional set value. See the usage below.</p>
<h3>Example:</h3>
<p>Consider a requirement in which you wish to send an email with few extra lines added to it if product A is ordered. And if contract term is 12 months then we need to add another T&amp;C statement in the email body.</p>
<p>Let&#8217;s implement that with both approaches&#8230;</p>
<h4>Approach 1: Few set value step and routing conditions to set process variables that get used in email body.</h4>
<h5>Process Diagram:</h5>
<div id="attachment_148" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.pandyaparth.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cucGFuZHlhcGFydGguY29tL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA5LzExL0FwcHJvYWNoMS5QTkc="><img class="size-medium wp-image-148" title="LC Set Value approach" src="http://blog.pandyaparth.com/wp-content/uploads/2009/11/Approach1-300x159.PNG" alt="Set Value - Route condition approach" width="300" height="159" /></a><p class="wp-caption-text">Set Value - Route condition approach</p></div>
<h5>Email body:</h5>
<blockquote><p>Dear Provisioning Team,</p>
<p>Please send the below details to John.</p>
<p>System:{$ /process_data/@System $}<br />
Agent Name:{$ /process_data/@Agentname $}<br />
Product ordered: {$ /process_data/@Product $}</p>
<p><span style="color: #ff0000;">{$ /process_data/@ProductAConfigurationDetails $}</span></p>
<p>Terms and Conditions:<br />
blah blah blah from Legal<br />
adf<br />
adf<br />
<span style="color: #ff0000;">{$ /process_data/@TCFor12MonthsContract$}</span><br />
blah<br />
blah</p>
<p>regards,<br />
BOH Team</p></blockquote>
<h4>Approach 2: Conditional set value with XPath</h4>
<h5>Process diagram:</h5>
<p><a href="http://blog.pandyaparth.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cucGFuZHlhcGFydGguY29tL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA5LzExL0FwcHJvYWNoMi5QTkc="><img class="alignnone size-medium wp-image-153" title="Set Value XPath approach" src="http://blog.pandyaparth.com/wp-content/uploads/2009/11/Approach2-300x123.PNG" alt="Set Value XPath approach" width="300" height="123" /></a></p>
<h5>Email Body</h5>
<blockquote><p>Dear Provisioning Team,</p>
<p>Please send the below details to John.</p>
<p>System:{$ /process_data/@System $}<br />
Agent Name:{$ /process_data/@Agentname $}<br />
Product ordered: {$ /process_data/@Product $}<br />
<span style="color: #ff6600;"><br />
<span style="color: #0000ff;">{$ substring(&#8216;This is where the actual text gets put about the product configuration&#8217;,<br />
50000000 * (number(/process_data/@Product !=&#8217;Product A&#8217;))<br />
) $}</span></span></p>
<p>Terms and Conditions:<br />
blah blah blah from Legal<br />
adf<br />
adf<span style="color: #339966;"><br />
<span style="color: #0000ff;">{$ substring(&#8217;12 Months T&amp;C content is written here or can be xpath expression&#8217;,<br />
50000000 * (number(/process_data/@ContractLength !=&#8217;12&#8242;))<br />
) $}</span></span><br />
blah<br />
blah</p>
<p>regards,<br />
BOH Team</p></blockquote>
<h3>Explanation:</h3>
<ul>
<li>The above expression marked in blue puts the text in email body if the condition at the end of it fulfills.</li>
<li>By moving this logic into the email step itself I could clean up the process design significantly. I believe that LC is too good to do data transformation but common&#8230;few set value and few conditional routes for a simple text insertion?? I reckon the XPath trick gives much more cleaner approach to solve this.</li>
<li>First thing to notice in the expression is the use of a large number <span style="color: #ff6600;"><span style="color: #0000ff;">50000000</span></span> . This is used to return blank substring value if the expression is false. Please adjust if your input text can be larger than this.</li>
<li>Second thing to notice is the use of comparison operator. I wanted to have 0 (zero) value for substring start value if condition is true. Boolean true is 1 so I&#8217;m using opposite operator. Eg. if(product=&#8221;Product A&#8221;) is represented as product!=&#8221;Product A&#8221;</li>
</ul>
<p>As this is an XPath based expression we can use it in any LC component. I tried implementing if-else clause as well but that didn&#8217;t turn out well.</p>
<p>If you managed to read through this much then I&#8217;m sure you would love to see the <span style="color: #ff0000;">undocumented &#8216;and&#8217; &#8216;or&#8217; keyword usage in XPath expression</span>. I found that while experimenting and it&#8217;s an instant hit among few of my fellow LC users. <a href="http://blog.pandyaparth.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cucGFuZHlhcGFydGguY29tLzIwMDkvMDcvaW50cm9kdWNpbmctbGMta2V5d29yZHMtbG9naWNhbC1vcGVyYXRvcnMtYW5kb3Iv" target=\"_self\">It can be found here</a>..</p>
<p>Let me know if you find this useful!!!!</p>
 <img src="http://blog.pandyaparth.com/wp-content/plugins/feed-statistics.php?view=1&post_id=146" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.pandyaparth.com/2009/11/conditional-set-value-using-xpath/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
