xsl-list
[Top] [All Lists]

RE: Using XSLT to add markup to a document

2003-07-07 09:48:27
David,

Of course you're also using recursion in your ingenious solution to this up-conversion problem -- it's just you're not recursing on a string-chop, but in a subtler way, asking the processor to process its own results.

Of course, this was forbidden in XSLT 1.0, so we're not in the habit of doing it. But we'll see an awful lot of it -- and very powerfully too, I bet -- when the node-set extension is no longer "questionable" in its application.

It's nicely done -- and I'll be interested (if/as XSLT 2.0 is rolled out) in all the upcoming discussion about the various implications of this kind of approach.

Cheers,
Wendell

At 11:25 AM 7/7/2003, you wrote:
Coming late to this thread, and I think everything has pretty much been
said, but had a query.

I notice that most XSLT 1.0 solutions use recursive templates and wondered
if there is any benefit in a solution that re-applies templates to text
nodes many times, rather than explicitly calling a recursive template.  For
moderately big files it seems to perform quite well, though I haven't tested
it too much, so there may be hidden problems.  I guess this approach is
essentially the same as recursion, but you don't have to figure out which
matched string comes first (though you do need node-set).


Mark_up_text.xml:

<node>
        <para>
This is a sample document that deals with markup of <emph>text</emph>.
</para>
        <para> When one applies <emph>markup</emph> to a large document, one
is faced with
a <def>time-consuming</def> effort.
</para>
        <para att="document markup">lkj markup kjlkj document lkj document
;lkj markup lkj;slakfj markup document</para>
</node>


Mark_up_text.xsl:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:msxml="urn:schemas-microsoft-com:xslt">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="text()" priority="2"><!-- need priority to overcome the
node match below -->
        <xsl:call-template name="markup">
                <xsl:with-param name="text" select="."/>
        </xsl:call-template>
</xsl:template>

<xsl:template match="node()|@*">
        <xsl:copy>
                <xsl:apply-templates select="@*"/>
                <xsl:apply-templates/>
        </xsl:copy>
</xsl:template>

<xsl:template name="markup">
        <xsl:param name="text"/>
        <xsl:choose>
                <xsl:when test="contains($text, 'document')">
                        <xsl:apply-templates
select="msxml:node-set(substring-before($text,'document'))"/>
                        <xsl:element name="special">document</xsl:element>
                        <xsl:apply-templates
select="msxml:node-set(substring-after($text,'document'))"/>
                </xsl:when>
                <xsl:when test="contains($text, 'markup')">
                        <xsl:apply-templates
select="msxml:node-set(substring-before($text,'markup'))"/>
                        <xsl:element name="special">markup</xsl:element>
                        <xsl:apply-templates
select="msxml:node-set(substring-after($text,'markup'))"/>
                </xsl:when>
                <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
        </xsl:choose>
</xsl:template>


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list