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

Posted on 2008-10-21
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)">
<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:value-of select="$Line3_Rtype02"/>
        <xsl:value-of select="$nl"/>

Open in new window

Question by:JohnnyOffTheSpot
  • 3
  • 2
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')">

Author Comment

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?
LVL 60

Accepted Solution

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"/>
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"/>

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

Author Closing Comment

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

Expert Comment

by:Geert Bormans
ID: 22776075

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mongodb hierarchy 2 59
Unable to resolve XML http request 4 98
SQL Result Set to XML 4 44
I'm using XML(xslt) - How to fix the BOM issue 5 12
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

792 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