Topic
  • 5 replies
  • Latest Post - ‏2012-11-07T07:35:01Z by Click_Apply
Click_Apply
Click_Apply
37 Posts

Pinned topic For-each X-path node How to call a processing rule

‏2012-10-30T12:58:58Z |
Hello,

I have a requirement, on a XB60. An inline XML with attachments, such as

<root>
<EmailMsg></EmailMsg>
<attachment>base64-encoded</attachment>
<attachment>base64-encoded</attachment>
<attachment>base64-encoded</attachment>
</root>

I want to run a processing rule which is common for all attachments

Can I call 'call Processing rule' inside For-each (advanced action) to take them out and process each attachment with one processing rule

In the post below Steve proposed an approach -

http://www.ibm.com/developerworks/forums/thread.jspa?threadID=322981

swlinn
Posts: 929
Registered: Oct 18, 2005 11:26:12 AM
Re: How to call a Processing Rule dynamically?
Posted: Mar 23, 2010 03:04:00 PM in response to: Liv2luv's post

As Arif points out, you must use a call action. What you could do is have your xsl store the name of the rule to call in a context variable. You could also have your xsl output something simple such as

<condition><call>true</call></conditional>

You could then have a conditional action use that as input and only reference a call action if the input context of /condition/call = 'true', and your call action would reference the context variable that has the name of the rule you wish to call.


I am struggling to get clarity of this approach. Any help is appreciated. An XSL snippet that achieves this objective would be great.

I have to go through this approach as 'dp:decode' throws me a Non-UTF error while base-64 decoding the attachments. HermannSW on DW in some post wrote he has a solution.. for UTF-8 error.. using ffd that approach with a enough detail is acceptable as well.

Regards
Updated on 2012-11-07T07:35:01Z at 2012-11-07T07:35:01Z by Click_Apply
  • swlinn
    swlinn
    1348 Posts

    Re: For-each X-path node How to call a processing rule

    ‏2012-10-30T13:54:41Z  
    The referenced post was for a conditional action, and this question was for a for-each action. In the case of a for-each that does a call action would specify your called rule (I'd assume you'd be calling the same rule for each of your three attachments). In your for-each, specify the xpath /root/EmailMsg/attachment that has a referenced call action that specifies your called rule. In that called rule, var://service/multistep/loop-iterator will have the attachment nodeset that matched the xpath. I suppose my question is what do you want to do with this attachment? If you are needing to do a transformation, then having a stylesheet using xsl:apply-templates with a template match on the attachment node would be a better approach.

    Regards,
    Steve
  • Click_Apply
    Click_Apply
    37 Posts

    Re: For-each X-path node How to call a processing rule

    ‏2012-10-30T14:07:29Z  
    • swlinn
    • ‏2012-10-30T13:54:41Z
    The referenced post was for a conditional action, and this question was for a for-each action. In the case of a for-each that does a call action would specify your called rule (I'd assume you'd be calling the same rule for each of your three attachments). In your for-each, specify the xpath /root/EmailMsg/attachment that has a referenced call action that specifies your called rule. In that called rule, var://service/multistep/loop-iterator will have the attachment nodeset that matched the xpath. I suppose my question is what do you want to do with this attachment? If you are needing to do a transformation, then having a stylesheet using xsl:apply-templates with a template match on the attachment node would be a better approach.

    Regards,
    Steve
    I want to just base-64 decode the the attachment and send it to the back-end. But, As I informed before using dp:decode throws a Non-UTF-8 error.

    I am trying to not use that function and create a context and POST to it using dp:url-open target attachment://context/xyz/cid:xyz and next with results action containing 'attachment://context/xyz/cid:xyz?Decode=base64 ' ==> OUTPUT which is working...

    Now I wanna iterate on this working processing rule for all my attachments.
  • swlinn
    swlinn
    1348 Posts

    Re: For-each X-path node How to call a processing rule

    ‏2012-10-30T14:28:15Z  
    I want to just base-64 decode the the attachment and send it to the back-end. But, As I informed before using dp:decode throws a Non-UTF-8 error.

    I am trying to not use that function and create a context and POST to it using dp:url-open target attachment://context/xyz/cid:xyz and next with results action containing 'attachment://context/xyz/cid:xyz?Decode=base64 ' ==> OUTPUT which is working...

    Now I wanna iterate on this working processing rule for all my attachments.
    It seems that what you want to do is a transformation action where the stylesheet is doing an identity like transformation using apply-templates. On your template match for "attachment", you'd do something like:

    <xsl:copy>
        <xop:Include href="cid:uniquecontent_id"/>
    </xsl:copy>
    <dp:url-open target="attachment://context/cid:uniquecontent_id" response="ignore">
        <xsl:value-of select="." />
    </dp:url-open>
    


    So essentially, you transform the attachment node, replacing the content with the xop:Include node. You may need to create a uuid for the "uniquecontent" part of the id. Then the url-open would be used to write the attachment. The iteration would be handled by the apply-templates of the stylesheet.

    Regards,
    Steve
    Updated on 2014-03-25T02:46:41Z at 2014-03-25T02:46:41Z by iron-man
  • Click_Apply
    Click_Apply
    37 Posts

    Re: For-each X-path node How to call a processing rule

    ‏2012-10-30T14:37:20Z  
    • swlinn
    • ‏2012-10-30T14:28:15Z
    It seems that what you want to do is a transformation action where the stylesheet is doing an identity like transformation using apply-templates. On your template match for "attachment", you'd do something like:

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr"><xsl:copy> <xop:Include href="cid:uniquecontent_id"/> </xsl:copy> <dp:url-open target="attachment://context/cid:uniquecontent_id" response="ignore"> <xsl:value-of select="." /> </dp:url-open> </pre>

    So essentially, you transform the attachment node, replacing the content with the xop:Include node. You may need to create a uuid for the "uniquecontent" part of the id. Then the url-open would be used to write the attachment. The iteration would be handled by the apply-templates of the stylesheet.

    Regards,
    Steve
    Thank you Steve, Will try and report back..
  • Click_Apply
    Click_Apply
    37 Posts

    Re: For-each X-path node How to call a processing rule

    ‏2012-11-07T07:35:01Z  
    • swlinn
    • ‏2012-10-30T14:28:15Z
    It seems that what you want to do is a transformation action where the stylesheet is doing an identity like transformation using apply-templates. On your template match for "attachment", you'd do something like:

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr"><xsl:copy> <xop:Include href="cid:uniquecontent_id"/> </xsl:copy> <dp:url-open target="attachment://context/cid:uniquecontent_id" response="ignore"> <xsl:value-of select="." /> </dp:url-open> </pre>

    So essentially, you transform the attachment node, replacing the content with the xop:Include node. You may need to create a uuid for the "uniquecontent" part of the id. Then the url-open would be used to write the attachment. The iteration would be handled by the apply-templates of the stylesheet.

    Regards,
    Steve
    Thank you Steve, Resolved using similar to proposed approach.

    Code Snippet of the approach

    <xsl:template name="substring-after-last">
    <xsl:param name="string"/>
    <xsl:param name="delimiter"/>
    <xsl:choose>
    <xsl:when test="contains($string, $delimiter)">
    <xsl:call-template name="substring-after-last">
    <xsl:with-param name="string"
    select="substring-after($string, $delimiter)" />
    <xsl:with-param name="delimiter" select="$delimiter"/>
    </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$string"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    <xsl:template name="substring-before-last">
    <xsl:param name="string"/>
    <xsl:param name="delimiter"/>
    <xsl:choose>
    <xsl:when test="contains($string, $delimiter)">
    <xsl:call-template name="substring-after-last">
    <xsl:with-param name="string"
    select="substring-before($string, $delimiter)" />
    <xsl:with-param name="delimiter" select="$delimiter"/>
    </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$string"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>
    ...

    <xsl:for-each select="//ws:Attachment">

    <!-- Get Attachment File Extension-->
    <xsl:variable name ="attachmentExtension">
    <xsl:call-template name="substring-after-last">
    <xsl:with-param name="string" select="ws:AttachmentFile/attribute::filename"/>
    <xsl:with-param name="delimiter" select="'.'"/>
    </xsl:call-template>

    <!-- Get Attachment File Name-->
    </xsl:variable>
    <xsl:variable name ="attachmentFileName">
    <xsl:call-template name="substring-before-last">
    <xsl:with-param name="string" select="ws:AttachmentFile/attribute::filename"/>
    <xsl:with-param name="delimiter" select="'.'"/>
    </xsl:call-template>
    </xsl:variable>

    <xsl:variable name ="attachmentFilenameOutputURL" select="concat($baseurl, $baseFilename, '.', $attachmentExtension, '?Encoding=base64')" />
    <dp:url-open target="{$attachmentFilenameOutputURL}" response="ignore">
    <xsl:value-of select = "ws:AttachmentFile"/>
    </dp:url-open>

    </xsl:for-each>