[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] normalize-space() except ...

Subject: Re: [xsl] normalize-space() except ...
From: "Syd Bauman s.bauman@xxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 9 Feb 2015 21:01:28 -0000

Yes, I suggest you post your code, or a small snippet thereof that
demonstrates the problem.

Certainly *just* normalizing space (on the <dd> content) doesn't
cause a problem, but it also doesn't get you the <ss:font> elements.

And while I'm sympathetic in theory to not wanting to write your own
sorta-normalize-space() function, I have to admit I've done so on
more than one occasion:

  <xsl:function name="wwp:regularize-space" as="xs:string">
    <xsl:param name="arg" as="xs:string"/>
    <xsl:variable name="intermediate" select="concat('b ', $arg, 'b ')"/>
    <xsl:variable name="semifinal" select="normalize-space($intermediate )"/>
    <xsl:value-of select="substring( $semifinal, 2, string-length($semifinal )
-2 )"/>

> So I have some mixed content that has a wide variety of whitespace
> useage that I need to normalize/simplify because the receiving
> system is not ignoring it, even though the input is an XML file.
> Receiving system is Open Office Calc using the MS XML Spreadsheet
> xml format.
> For the most part normalize-space is doing the trick until it hits
> mixed content. So I have something like this for input:
> <dd><p>
>          This is my text
> with <i>italics content</i> with other text.
> </p></dd>
> My output is coming out like this:
> <ss:Data>This is my text with<ss:font italics="yes">italics
> content</ss:font>.</ss:Data>
> Which results in "... text withitalics contentwith other text."
> My content is simple enough that I can probably check for
> following::sibling being certain elements and then just add a space back
> in, and then with the content of the <i> element I would have to analyze
> the following content and if text() look to see if the first character is
> punctuation.
> I'm just wondering if there is a better solution for handling this in XSLT
> than basically writing my own normalize-space function. The real solution
> would be to get the importing tool to handle the text properly and
> normalize on import, but that is not an option.
> Any suggestions?

Current Thread