Re: [xsl] Dynamic dispatch of functions/templates (was matching text() )

Subject: Re: [xsl] Dynamic dispatch of functions/templates (was matching text() )
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 27 Dec 2010 12:42:23 -0500
Hi again David,

On 12/23/2010 11:45 AM, Michael Kay wrote:
On 23/12/2010 14:37, David Lee wrote:
Still thinking how to change

<xsl:apply-templates select="text()"/>

<xsl:template match="some_xpath/text()">

Into something where the text is concatenated in the face of PI's or comments.

It sounds as if there's a back-story to this one which perhaps I should
have been following, but on the face of it, you can simply do

<xsl:variable name="temp">
<xsl:for-each select="text()"><xsl:value-of select="."/></xsl:for-each>
<xsl:apply-templates select="$temp/text()"/>

perhaps with a mode.

I don't really follow the logic of how your stated requirement leads to
a need for dynamic despatch.

Also, I think you should simply consider

<xsl:apply-templates select="." mode="handle-text"/>

I.e., a dedicated mode that does what you intend to do with the text content.

In other words, I think you may have answered your own question.

No, it doesn't have the context of any of the text nodes, but of the parent element. But you could have

<xsl:template match="*" mode="handle-text">
  <xsl:for-each select="text()">
    ... etc.

And yes, if you have only this single template in the mode, you could use a named template instead (or even collapse the call entirely).

I admit I'm fumbling in the dark (as are we all) without a fuller description of requirements. But I also suspect that you are close to a solution -- and that the essential problem is to distinguish text-content elements (containing only PCDATA, comments and PIs, where you can do this sort of thing without concern for data integrity) from mixed-content elements (where you can't) ... and again, your schema can help you with that.


Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
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