xsl-list
[Top] [All Lists]

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

2015-02-09 15:01:41
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('␠', $arg, '␠')"/>
    <xsl:variable name="semifinal" select="normalize-space($intermediate )"/>
    <xsl:value-of select="substring( $semifinal, 2, string-length($semifinal ) 
-2 )"/>
  </xsl:function>


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?
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>