This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

normalize-space(me)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]