[xsl] testing for variable amounts of whitespace?

Subject: [xsl] testing for variable amounts of whitespace?
From: bill french <bill@xxxxxxxxxxxxxxxx>
Date: Fri, 27 Apr 2001 14:02:40 -0400
hi all,

first - the problem: i'm building an xml doc from a database. some of
the fields contain variable amounts of whitespace. whenever my
stylesheet comes across a node containing only whitespace, i'd like to
turn it all into one html non-breaking space entity (&nbsp;). (i'm
already stripping whitespace from nodes whose values aren't
whitespace-only with the normalize-space() function.)

second - the questions: can i write an xpath expression to test for a
variable amount of whitespace? how would i do such a thing?

third - the relevent info: parser: MSXML 3 working in conjunction with
microsoft's xslisapi dll for IIS.

i'm pretty new to all of this; please forgive my ignorance.



ahh yes, the xml:

<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" server-config="sampleconfig.xml" ?>

<employee id="100" status="A">
  <firstName>George  </firstName>
  <middleName>    </middleName>
  <lastName>Bush  </lastName>
  <emailAddress>george@xxxxxxxxxxxxxx    </emailAddress>
  <homePhone>202-456-9999    </homePhone>
  <mobilePhone>             </mobilePhone>
  <address id="1"/>


and the stylesheet:

<?xml version="1.0" ?> 

<xsl:template match="/">
  .sans {font-family:verdana; font-size:12px;}
  .sansBigger {font-family:verdana; font-size:14px;}
  <title>example two - using xsl:apply-templates</title>
<body bgcolor="#ff9400" text="#ffff33">
<table bgcolor="#ffff33" border="0" cellpadding="0" cellspacing="0">
<td><table border="0" bgcolor="#ff9400" cellpadding="8" cellspacing="1">
  <tr bgcolor="#f58000">
    <td class="sansBigger" nowrap="nowrap"><b class="sansBigger" >first
    <td class="sansBigger" nowrap="nowrap"><b>middle name</b></td>
    <td class="sansBigger" nowrap="nowrap"><b>last name</b></td>
    <td class="sansBigger" nowrap="nowrap"><b>email address</b></td>
    <td class="sansBigger" nowrap="nowrap"><b>home phone</b></td>
    <td class="sansBigger" nowrap="nowrap"><b>mobile phone</b></td>

  <xsl:apply-templates select="nsEmployees/employee">
    <xsl:sort select="lastName" />


<xsl:template match="employee">
  <xsl:if test="@status = 'A'">
      <xsl:apply-templates select="firstName" />
      <xsl:apply-templates select="middleName" />
      <xsl:apply-templates select="lastName" />
      <xsl:apply-templates select="emailAddress" />
      <xsl:apply-templates select="homePhone" />
      <xsl:apply-templates select="mobilePhone" />

<xsl:template match="firstName">
    <td class="sans">
      <xsl:if test="">

      <xsl:value-of select="normalize-space()" /></td>

<xsl:template match="middleName">
    <td class="sans"><xsl:value-of select="normalize-space()" /></td>

<xsl:template match="lastName">
    <td class="sans"><xsl:value-of select="normalize-space()" /></td>

<xsl:template match="emailAddress">
    <td class="sans"><xsl:value-of select="normalize-space()" /></td>

<xsl:template match="homePhone">
    <td class="sans"><xsl:value-of select="normalize-space()" /></td>

<xsl:template match="mobilePhone">
    <td class="sans"><xsl:value-of select="normalize-space()" /></td>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread