Solved

Need XSL code to skip output if a condition is met in a tag, again.

Posted on 2008-10-21
5
296 Views
Last Modified: 2013-11-18
Gertone answered this question previously with the attached code.
This code has worked wonders for those tags that are empty or have differing amounts of characters in them.
I have finally stumbled upon a tag that will contain either an X or an N.  If it contains an X, that I have to skip that line from being printed.
I have tried variations of the following:
<xsl:if test="contains(normalize-space(Rtype01), X)">
and
<xsl:if test="match(normalize-space(RateTypeMinBill), X)">
Even if I get past the syntax errors, it just prints my line regardless.
  I think what I need to do is say something like, if test="match..... then call the normalize-space function but I am doing something(many things, all things) wrong.

Thanks in advance for any help.
<xsl:value-of select="$Line1_AppNumber"/>
        <xsl:value-of select="$nl"/>
        <xsl:if test="string-length(normalize-space(Rtype01)) > 0">
            <xsl:value-of select="$Line2_Rtype01"/>
            <xsl:value-of select="$nl"/>
        </xsl:if>
        <xsl:value-of select="$Line3_Rtype02"/>
        <xsl:value-of select="$nl"/>

Open in new window

0
Comment
Question by:JohnnyOffTheSpot
  • 3
  • 2
5 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22773724
you are testing the value of the element X,
you should test for string values (add single quotes)
and no need for the normalize-space in the test
<xsl:if test="contains(Rtype01, 'X')">
0
 
LVL 2

Author Comment

by:JohnnyOffTheSpot
ID: 22775264
i'm so confused.  I thought that the normalize-space was what was removing the line if the condition was met.
Why does this remove the line then?
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 22775706
normalize-space() gets rid of spurious white-space in the string value of the node or string in its argument.
the line is removed because you make outputting the line depending on the result of a test.
In this example:
        <xsl:if test="string-length(normalize-space(Rtype01)) > 0">
            <xsl:value-of select="$Line2_Rtype01"/>
            <xsl:value-of select="$nl"/>
        </xsl:if>
the normalize space removes all trailing and leading spaces, so a single or more spaces would become nothing
and it is added to make the "> 0" test more secure
the two value-of statements happen when the stringlength of Rtype01 is more than 0 (after removing spaces)

Now in the new case you only want to know whether there is an 'X' in order to continue,
hence the test
        <xsl:if test="contains(Rtype01, 'X')">
            <xsl:value-of select="$Line2_Rtype01"/>
            <xsl:value-of select="$nl"/>
        </xsl:if>

of course you don't need the string length test in combination with this, since if it contains an 'X', it is longer than zero characters
0
 
LVL 2

Author Closing Comment

by:JohnnyOffTheSpot
ID: 31508614
above and beyond.  Thank you again, Gertone!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22776075
welcome
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
React or Angular? 6 73
Animated .jpg? 13 80
Download a website to hdd 2 68
Shredding xml into an oracle 11g Database 2 46
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question