Subject: RE: [xsl] Using XSLT to add markup to a document From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Mon, 07 Jul 2003 12:48:27 -0400 |
Cheers, Wendell
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@xxxxxxxxxxxxxxxx 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 ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Using XSLT to add markup , McNally, David | Thread | RE: [xsl] Using XSLT to add markup , Wendell Piez |
RE: [xsl] Using XSLT to add markup , McNally, David | Date | [xsl] XSLT multiple output files, Hung Nguyen |
Month |