Title: Splitting elements round empty tags

Hello,

I have a problem with XSLT and/or Cocoon that I really don't know how to solve. Starting point is following: I have a file with elements <titre>, <intro>, <texte>, and so on. Each of these elements is broken, or can be broken, in paragraphs with the empty element <br/>. I would better have one <titre>, <intro>, and so on, element per paragraph and no <br/> no more.

<?xml version="1.0"?>
<document>
    <titre>
        some text here
        <br/>
        that is part of title
        <br/>
    </titre>
    <texte>
        some other text here
        <br/>
        that is part of the text
        <br/>
        broken in differents paragraphs
        <br/>
        with a last unnecessary break line
        <br/>
    </texte>
</document>

OK, I transform this with following XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="br">
        <xsl:text disable-output-escaping="yes">&lt;/</xsl:text>
        <xsl:value-of select="name(..)"/>
        <xsl:text disable-output-escaping="yes">&gt;</xsl:text>
        <xsl:text disable-output-escaping="yes">&lt;</xsl:text>
        <xsl:value-of select="name(..)"/>
        <xsl:text disable-output-escaping="yes">&gt;</xsl:text>
    </xsl:template>
    <xsl:template match="@*|node()" priority="-1">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

That gives me the result I was expecting for:

<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
    <titre> some text here </titre>
    <titre> that is part of title </titre>
    <titre></titre>
    <texte> some other text here </texte>
    <texte> that is part of the text </texte>
    <texte> broken in differents paragraphs </texte>
    <texte> with a last unnecessary break line </texte>
    <texte></texte>
</document>

But then I'm trying to get rid of the empty elements with a second XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="@*|node()">
        <xsl:if test="string(.)">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

And the result I get is somewhat disappointing:

<document>
    <titre> some text here &lt;/titre&gt;&lt;titre&gt; that is part of title &lt;/titre&gt;&lt;titre&gt;
    </titre>
    <texte> some other text here &lt;/texte&gt;&lt;texte&gt; that is part of the text &lt;/texte&gt;&lt;texte&gt; broken in differents

        paragraphs &lt;/texte&gt;&lt;texte&gt; with a last unnecessary break line &lt;/texte&gt;&lt;texte&gt;
    </texte>
</document>

That means all the tags that before appeared correctly as tags look now as if they were just text.

How is this possible? My sitemap.xmap looks as following:

<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
    <map:components>
        <map:generators default="file"/>
        <map:transformers default="xslt"/>
        <map:readers default="resource"/>
        <map:serializers default="html"/>
        <map:selectors default="browser"/>
        <map:matchers default="wildcard"/>
    </map:components>
    <map:pipelines>
        <map:pipeline>
            <map:match pattern="probleme.xml">
                <map:generate  src="">
                <map:transform src="">
                <map:transform src="">
                <map:serialize type="xml"/>
            </map:match>
        </map:pipeline>
    </map:pipelines>
</map:sitemap>

I suppose the error is in my first XSLT. It would be right if the point was to save a file on disk, but it doesn't work in a pipeline. But a really don't see how I could rewrite this XSLT using <xsl:element>!

Thanks for help,
Philippe

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to