Solved

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 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

10 Experts available now in Live!

Get 1:1 Help Now