1

Basically the email uses XSLT AMPScript to parse XML into the email. Part of the requirement is to count the items in the XML data and perform certain logics based on the item count.

Since XSL uses the XPath to count the item iteration and AMPScript sets the variable with a static field which is then used in the business logics.

For eg: If the item count is more than 10 then the image width and table with will change.

Here is the sample code:

    %%[
/*<!--*/
VAR @ItemCount, @WidthTD, @Breaks
SET @ItemCount = "<xsl:value-of select='count(message/additional-content/order/order-snapshot/items/item)' />"
IF (@ItemCount>9) THEN
  SET @WidthTD = 37
  SET @WidthTB = 300
  SET @Breaks = '&#44;&#32;'
ELSE
  SET @WidthTD = 143
  SET @WidthTB = 200
  SET @Breaks = '<br/>'
ENDIF
/*-->*/
]%%

However, the operators '<' and '>' seems to have error within the AMPScript function. My assumption is that the xslt validation is causing the error around the operators. Also the error seems to be fixed if '==' operator is used.

Here is the work around I have got but involves different comparison operators. Below code counts the length of the item counts which is not an ideal solution.

%%[IF (Length(@ItemCount)==2) OR (Length(@ItemCount)==3) THEN
  SET @WidthTD = 37
ELSE
  SET @WidthTD = 143
ENDIF]%% 

Is there any way of bypassing the validation error around the '<' and '>' operators in AMPScript within XSLT template?

Also here is the error after using the '<' and '>' comparison operators.

The script condition contains an invalid comparison operator. Condition: @ItemCount>=10

  • One thing to try is the entity form &lt; and &gt; – Keith C Sep 3 '17 at 9:39
  • Yes I have noticed that and I have tried it. Doesn't seem to work. – Brad Sapkota Sep 3 '17 at 9:51
  • @itemCount must not be an integer, find out the data it contains, pretty sure your comparing something that is NOT an integer with the number 10 – thechrishaddad Sep 3 '17 at 16:31
  • @thechrishaddad xsl output for count within the Xpath gives a number value. my concern is more around the comparison operators which is the issue due to xslt validation. – Brad Sapkota Sep 3 '17 at 23:22
0

In your first script there is also a problem with unescaped quotes as you use double quotes for the string you assign to your AMPscript variable as well as for the attributes in your XSL.

The HTML-editor in Marketing Cloud also has a problem with comparison operators, but there is a workaround which could also help in your case: Try using a comment surrounding your AMPscript code:

%%[
  /*<!--*/ 
    Var @count, @output
    Set @count = 2

    IF @count > 0 THEN
        Set @output = "greater than 0"
    ELSEIF @count < 1 THEN
        Set @output = "less than 1"
    ENDIF
  /*-->*/
]%%

Related info:

| improve this answer | |
  • I have used your method and it didn't seem to throw any error but the ampscript didn't work either. Sample code above in my original post. thanks – Brad Sapkota Sep 3 '17 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.