Solved

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

Posted on 2008-10-21
5
295 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now