normalize-space for entire document?

Does anyone have an idea how to use normalize-space for an entire document? I have a mixutre of element and mixed nodes, and keeping the mixed nodes proper has been difficult.

TIA
LVL 11
kmartin7Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
<xsl:strip-space elements="*"/>
<xsl:preserve-space elements="elements go here space seperated"/>

tends to work, in the preserve space you could put the mixed content elements, for whom space preservation is important
that ofcourse doesn't normalize the whitespace inside PCDATA streams
note that msxml and xml spy do the wrong thing with whitespace only text nodes

or you could make a multi-pass, with the second pass being an identity transform that normalize-spaces every text node
in XSLT2, you can easily add both passes inone stylesheet
(or you could do that using node-set() if your processor supports that)
0
kmartin7Author Commented:
Hi Geert,

For some reason, I have never been able to get that to work. I have tried it on different parsers with the same result each time. Here is a snippet. As you can see, we would like to remove all that extra space for the authors.

Thanks.
<para>Text and more text (
      
        
          
          
          <xref type="figure" idref="i0f3a011"></xref>) text and more text:
    
      
        
        
        </para>

Open in new window

0
Geert BormansInformation ArchitectCommented:
try this

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   
    <xsl:output indent="yes"/>
   
    <xsl:preserve-space elements="para"/>
     
    <xsl:template match="*">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
   
    <xsl:template match="text()">
        <xsl:value-of select="normalize-space(.)"/>
    </xsl:template>
</xsl:stylesheet>


I have the indent=yes in the output element, to make sure that not everything is on one line
This way you would loose spaces in front of, or right after mixed content elements, such as <emphasis>
I bet that is not acceptable
you could have a special template for all mixed content elements such as emphasis,
to copy the space back in
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kmartin7Author Commented:
Yeah, it doesn't quite give us what we need. It is just a bad having all collapse. We are just going to use SS with the editor options and then run a series of find/replace to add spaces before and after certain instances.

Thanks anyway.

Kurt
0
Geert BormansInformation ArchitectCommented:
cheers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.