Re: [xsl] How to Handel whitespace in xsl:if test

Subject: Re: [xsl] How to Handel whitespace in xsl:if test
From: "M. David Peterson" <xmlhacker@xxxxxxxxx>
Date: Sun, 4 Jun 2006 03:28:02 -0600
I agree, the question as asked, is a little too non-specific, but the
answer I don't think is going to help ...

e.g. <xsl:if test="normalize-space('Adult education')" ... /> will
output the exact same input string, so unless you purposely added
spaces in abnormal places,

e.g. <xsl:if test="normalize-space(' Adult education ')" ... />

then theres not a whole lot of purpose in using the normalize-space
function in the first place.

Of course, you (Alexander) obviously recognize this, so I guess my
point is to suggest to Oknam that a bit more information is needed to
properly answer the question.

If I were to guess, I would assume that you (Oknam) are attempting to
test the string value of a particular element e.g <department> Adult
education </department>, and want to make sure that any
inconsistencies in white space can be properly handled such that,

<department> Adult education </department>

and

<department>Adult education</department> would evaluate to the same
string literal?

If yes, take Alexander's code and slightly modify it,

<xsl:if test="normalize-space(.) = 'Adult education'">
<!-- add your code here to output the proper value -->
</xsl:if>

where . represents the current context node.

If you are testing an attribute value or a child of the current
context node, then use @attributeName or childname as such,

<xsl:if test="normalize-space(@attributeName) = 'Adult education'">
<!-- add your code here to output the proper value -->
</xsl:if>

or

<xsl:if test="normalize-space(childname) = 'Adult education'">
<!-- add your code here to output the proper value -->
</xsl:if>

where attributeName and childname would be replaced by the actual
attribute or child name.

Of course its possible to test the value of any node and/or attribute
value within the context of the current XML document being processed,
but let's start with the above and hope that this does the trick.  If
no, then there are plenty of folks here to help you with this
particular type of problem, but I'll assume yes unless you suggest
otherwise.

On 6/4/06, Alexander Johannesen <alexander.johannesen@xxxxxxxxx> wrote:
Hi,

On 6/4/06, oknam park <ponda7777@xxxxxxxxxxx> wrote:
> xsl:if test="Adult education"
>
> Could you let me know how to handle whitespace here?

In your example you're testing for something that never will be true.
If you mean, testing for string literals, try something like ;

<xsl:if test="normalize-space('Adult education')" ... />


Alex -- "Ultimately, all things are known because you want to believe you know." - Frank Herbert __ http://shelter.nu/ __________________________________________________




--
<M:D/>

M. David Peterson
http://www.xsltblog.com/

Current Thread