Subject: RE: Normalizing string containing entities From: "Pierre-Yves Saumont" <pys@xxxxxxxx> Date: Fri, 14 Jul 2000 15:24:18 +0200 |
Thank you for your help. I will search in the archive. (Unfortunately, here, the final output format is MIF, in which normalisation can't be done.) Pierre-Yves -----Message d'origine----- De : owner-xsl-list@xxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxx]De la part de David Carlisle Envoyé : vendredi 14 juillet 2000 14:37 À : xsl-list@xxxxxxxxxxxxxxxx Objet : 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 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Normalizing string containing e, David Carlisle | Thread | Re: Normalizing string containing e, Imran Rashid |
RE: Flattening a tree, Pierre-Yves Saumont | Date | Re: One XSL combining to different , SoftLiban DACCACHE W |
Month |