Solved

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

Posted on 2008-10-21
5
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML XSL Choose example 3 38
I'm using XML(xslt) - How to fix the BOM issue 5 23
Need a modeling tool 2 41
Retreiving SOAP FAULT messages using classical ASP 14 29
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…
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.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

749 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