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

normalize-space(me)

Subject: normalize-space(me)
From: Mike Ferrando <mikeferrando@xxxxxxxxx>
Date: Mon, 17 Jun 2002 05:54:09 -0700 (PDT)
concat normalize space
Dear friends, 
I am trying to normalize the hard returns, tabs and extra spaces in
nodes that have children. I have tried a number of different usages
of normalize-space() but nothing seems to work.

I began to use normalize-space in an effort to dectect errors in
coding legacy finding aids. Some elements would only have nested
nodes and some nodes would only have text. So I used normalize-space
to find these errors (text where it should not be in the xml
document). I used node()[normalize-space(.)]. This would allow me to
find text in a node no matter where it appeared, before or after any
children in the node. But now I am not so sure that it works
correctly.

Initally my object was to create a template that would detect any
children of the current node it was processing. In this instance the
node is TITLE.  If there was a child node, then it would use
xsl:copy-of, but if not it would call the node with xsl:value-of.

I then wanted to normalize the space within the node so that even if
there was a child node any line breaks, tabs or extra spaces would be
normalized into one line.

Of course this code is created for testing real documents.

Could anyone help me out. I thought I might use translate() but I am
not sure if I really need to do that.

Sincerely,
Mike Ferrando
Washington, DC

What I have is:
<TT>
  <T1>
    <TITLE>This is a  normal 
title</TITLE>
  </T1>
  <T1>
    <TITLE>This is 
<S>not</S> a normal title</TITLE>
  </T1>
</TT>

This is what I want:
<TITLE>This is a normal title</TITLE>
<TITLE>This is <S>not</S> a normal title</TITLE>

This is my xsl:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet   version="1.0"  
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output version="1.0" method="xml" indent="yes" encoding="utf-8"
omit-xml-declaration="no" standalone="no" media-type="text/xml"/>

<!-- Indent turned off -->

<xsl:template match="/">
  <xsl:text>&#xA;</xsl:text>
  <xsl:comment>
    <xsl:value-of select="concat(' Transformed with ', $replace,
'.xsl ')"/>
  </xsl:comment>
  <xsl:text>&#xA;</xsl:text>
  <C01>
    <xsl:apply-templates select="//T1"/>
    <xsl:text>&#xA;</xsl:text>
  </C01>
</xsl:template>

<xsl:template match="T1">
  <xsl:text>&#xA;</xsl:text>
  <T1>
    <xsl:apply-templates select="TITLE"/>
    <xsl:text>&#xA;</xsl:text>
  </T1>
</xsl:template>

<xsl:template match="TITLE">
  <xsl:variable name="nest" select="child::*/node()"/>
  <xsl:text>&#xA;</xsl:text>
  <TITLE>
    <xsl:choose>
      <xsl:when test="$nest">
        <xsl:copy-of select="concat('nnn', $nest, 'nnn',
node()[normalize-space(.)])"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="concat('nnn', $nest, 'nnn',
normalize-space(node()))"/>
      </xsl:otherwise>
    </xsl:choose>
  </TITLE>
</xsl:template>

</xsl:stylesheet>

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

 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.