[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

testing for variable amounts of whitespace?

Subject: testing for variable amounts of whitespace?
From: bill french <bill@xxxxxxxxxxxxxxxx>
Date: Fri, 27 Apr 2001 14:02:40 -0400
xsl whitespace test
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.

thanks,

--bill

ahh yes, the xml:

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

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

---

and the stylesheet:

<?xml version="1.0" ?> 
<xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0"
>

<xsl:template match="/">
<html>
<head>
  <style>
  .sans {font-family:verdana; font-size:12px;}
  .sansBigger {font-family:verdana; font-size:14px;}
  </style>
  <title>example two - using xsl:apply-templates</title>
</head>
<body bgcolor="#ff9400" text="#ffff33">
<table bgcolor="#ffff33" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><table border="0" bgcolor="#ff9400" cellpadding="8" cellspacing="1">
  <tr bgcolor="#f58000">
    <td class="sansBigger" nowrap="nowrap"><b class="sansBigger" >first
name</b></td>
    <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>
  </tr>

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

</table></td>
</tr>
</table>
</body>
</html>
</xsl:template>

<xsl:template match="employee">
  <xsl:if test="@status = 'A'">
  <tr>
      <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" />
  </tr>
  </xsl:if>
</xsl:template>

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

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

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

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

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

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

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

</xsl:stylesheet>

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.