[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Normalizing string containing entities
> Does anyone know a simple way to normalise strings containing entities and > subelement ? entities are no problem as they are all expanded before XSL sees the document. normalising space in mixed content is _always_ a problem. Of course normally you just don't do it, as the renderer (eg html in this case) can more easily do it as it lays out the characters, after all the markup is gone. If you do want to do it within the markup, the problem as stated was underspecified, but here is a possible (probably partial) solution. As always documented to the "literate programming" standards discussed in an earlier thread on this list. David <x> <para>Some text <em>some other text</em> remaining text</para> <para>Some text<em> some other text</em> remaining text</para> <para>Some text <em> some other text</em> remaining text</para> <para>Some text <em>some other text </em> remaining text</para> <para>Some text <em>some other text </em>remaining text</para> <para> Some text <em>some other text</em> remaining text </para> </x> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" > <xsl:output method="xml" indent="yes"/> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="para/text()"> <xsl:value-of select="normalize-space(.)"/> <xsl:if test="contains(concat(.,'^$%'),' ^$%') and following-sibling::* and not(following-sibling::*[1]/node()[1][self::text() and starts-with(.,' ')])"> <xsl:text> </xsl:text> </xsl:if> </xsl:template> <xsl:template match="para/*/text()"> <xsl:if test="starts-with(.,' ')"><xsl:text> </xsl:text></xsl:if> <xsl:value-of select="normalize-space(.)"/> <xsl:if test="contains(concat(.,'^$%'),' ^$%') or ../following-sibling::node()[1][self::text() and starts-with(.,' ')]"> <xsl:text> </xsl:text> </xsl:if> </xsl:template> </xsl:stylesheet> bash-2.01$ xt normsp.xml normsp.xsl <?xml version="1.0" encoding="utf-8"?> <x> <para>Some text <em>some other text </em>remaining text</para> <para>Some text<em> some other text </em>remaining text</para> <para>Some text<em> some other text </em>remaining text</para> <para>Some text <em>some other text </em>remaining text</para> <para>Some text <em>some other text </em>remaining text</para> <para>Some text <em>some other text </em>remaining text</para> </x> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|