Background Color:
 
Background Pattern:
Reset
Search

Forum

Please Log In

We want you to contribute! 

This forum is a moderated environment. 
We try to keep it neat and tidy. In order to access the forum content we would like you to either or register.

HomeHomeScryberScryberDevelopment Que...Development Que...data:If test string-length doesn't workdata:If test string-length doesn't work
Previous
 
Next
New Post
3/16/2017 8:32 PM
 

I'm trying to check for an empty string.  the string-length function always returns zero.  Doesn't matter what the actual value of TargetText is.  What am I missing?

                             <data:If test="string-length(@TargetText) = 0">
                              <Template>
                                <pdf:Li style:class="bold">
                                  Keep doing what you are doing - Excellent job!
                                </pdf:Li>
                              </Template>
                            </data:If>
                            <data:If test="string-length(@TargetText) > 0">
                              <Template>
                                <pdf:Li style:class="bold">
                                  To improve, <pdf:Label text="{xpath:TargetText}"/>
                                  <pdf:Br/>
                                  <pdf:Span style:font-italic="true" style:font-bold="false">
                                    This target has to do with
                                    <pdf:Label style:class="bold" text="{xpath:@SkillName}"/> and your
                                    <pdf:Label text="{xpath:@TargetDescription}"/>
                                  </pdf:Span>
                                </pdf:Li>
                              </Template>
                            </data:If>
  

 
New Post
3/18/2017 9:35 AM
 

The string-length function should work as it is standard out of the box.

However - check the actual value on the @TargetText node as string-length([null]) = 0 will always true.

 
New Post
3/18/2017 4:45 PM
 

Yes, the string is certainly non-null  I can successfully print it after the test fails.

 
New Post
3/20/2017 8:25 AM
 

Ok - you can try and intercept the value with the a label before the test.

<pdf:Label text='string-length(@TargetText)' />
<pdf:Label text='@TargetText' />

The string-length function should work within the XPath Expression.

If you post your data schema and more of the template Xml then it might be easier to diagnose.

Richard

 
New Post
3/20/2017 3:16 PM
 

OK.  Here's some additional script.  You can see that I print out TargetText as a label, right before the test:

            <pdf:Div style:class="targets">
              <pdf:H6>Comments and Targets: </pdf:H6>
              <data:ForEach  select="Summaries/AflSummary/Questions/AflQuestion">
                <Template>
                  <pdf:Label text="{xpath:@QuestionName}"/>
                  <pdf:Br/>
                  <pdf:Label style:font-italic="true" text="{xpath:Comment}"/>
                  <pdf:Ul>
                    <data:ForEach select="TargetMeta/TargetList/AflTarget">
                      <Template>
                        <data:If test="@TargetIsPriority = 'true'">
                          <Template>
                            <pdf:Li style:class="bold">
                              <pdf:Label text="{xpath:TargetText}" />
                            </pdf:Li>
                            <data:If test="string-length(@TargetText) = 0">
                              <Template>
                                <pdf:Li style:class="bold">
                                  Keep doing what you are doing - Excellent job!
                                </pdf:Li>
                              </Template>
                            </data:If>
                            <data:If test="string-length(@TargetText) > 0">
                              <Template>
                                <pdf:Li style:class="bold">
                                  To improve, <pdf:Label text="{xpath:TargetText}"/>
                                  <pdf:Br/>
                                  <pdf:Span style:font-italic="true" style:font-bold="false">
                                    This target has to do with
                                    <pdf:Label style:class="bold" text="{xpath:@SkillName}"/> and your
                                    <pdf:Label text="{xpath:@TargetDescription}"/>
                                  </pdf:Span>
                                </pdf:Li>
                              </Template>
                            </data:If>
                          </Template>
                        </data:If>
                        <data:If test="@TargetIsPriority = 'false'">
                          <Template>
                            <!--<data:If test="string-length(@TargetText) = 0">
                              <Template>
                                <pdf:Li>
                                  Keep doing what you are doing - Excellent job!
                                </pdf:Li>
                              </Template>
                            </data:If>
                            <data:If test="string-length(@TargetText) > 0">
                              <Template>-->
                                <pdf:Li>
                                  To improve, <pdf:Label text="{xpath:TargetText}"/>
                                  <pdf:Br/>
                                  <pdf:Span style:font-italic="true" style:font-bold="false">
                                    This target has to do with
                                    <pdf:Label style:class="bold" text="{xpath:@SkillName}"/> and your
                                    <pdf:Label text="{xpath:@TargetDescription}"/>
                                  </pdf:Span>
                                </pdf:Li>
                              <!--</Template>
                            </data:If>-->
                          </Template>
                        </data:If>
                      </Template>
                    </data:ForEach>
                  </pdf:Ul>
                </Template>
              </data:ForEach>
            </pdf:Div>

 

 

This results in the following.  As you can see, TargetText is "choose a topic with clear relevance to the course. ", but the test for string-length = 0 succeeds, so "Keep doing what you are doing" also prints out.

Comments and Targets: 

1 Paper content 

• choose a topic with clear relevance to the course. 

• Keep doing what you are doing - Excellent job! 


 


 
New Post
3/20/2017 6:02 PM
 

Hi

It could be the copy and paste, but your label is referring to the element TargetText, but your string-length test is trying to refer to an attribute @TargetText. This could cause the issue.

Richard

 
New Post
3/20/2017 9:10 PM
 

Aha!  Yes, removing the '@' works. Thank you!

I was referring to this thread - that's where I got the '@' from:

What is the syntax for If condition?

 
Previous
 
Next
HomeHomeScryberScryberDevelopment Que...Development Que...data:If test string-length doesn't workdata:If test string-length doesn't work