Altova Mailing List Archives


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

From: "M. David Peterson" <xmlhacker@--------->
To:
Date: 6/4/2006 9:33:00 AM
correction:



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

Wouldn't output anything...  Again, not that either of you didn't know
this.  Just wanted to correct my own error in suggesting that it would
output the same as the input string... Obviously, thats not the case.
:)

On 6/4/06, M. David Peterson <xmlhacker@xxxxxxxxx> wrote:
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/





--
<M:D/>

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

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.