xsl-list
[Top] [All Lists]

Re: FW: Dealing with mixed content

2005-02-15 11:47:34
Tempore 19:31:36, die 02/15/2005 AD, hinc in xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit Paul Clarke <pclarke(_at_)rcpsolutions(_dot_)com>:

Hello,

Apologies inadvance for the 'XSL 101' nature of this question but I'm new to
XSL.

I receive XML from an automate conversion process, over which I have no
control.

Example:

        <block >Text <font font-weight="bold">more text</font> more
text<sr/>more text. <hr/>more text <sr/>more text.</block>

The <sr/> elements can be ignored but the <hr/> element indicates that an
exisitng <P> element should be terminated and a new <P> element started.

From the above sample the output would be:

        <P>Text <f>more text</f> more text more text. </P>
        <P>more text more text</P>

Hi,

This is a grouping problem. Numerous techniques are available for solving problems like this.

Here you have one:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output method="xml" indent="yes"/>

<xsl:key name="group" match="node()" use="generate-id((.. | preceding-sibling::hr)[last()])"/>

<xsl:template match="block">
        <xsl:copy>
                <xsl:for-each select="hr|.">
                        <p>
                                <xsl:apply-templates 
select="key('group',generate-id())"/>
                        </p>
                </xsl:for-each>
        </xsl:copy>
</xsl:template>

<xsl:template match="sr | hr"/>

<xsl:template match="font">
        <f>
                <xsl:apply-templates/>
        </f>
</xsl:template>

</xsl:stylesheet>


regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
Spread the wiki (http://www.wikipedia.org)

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



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