wrote:
> wrote:
> > You really should define 'do something', because the
> > solutions possible depend on what you're trying to do
> > with the elements.
> >
> > For example:
> >
> > <xsl:template match="text()[../@style='it']">
> > <i><xsl:copy/></i>
> > </xsl:template>
> >
> > This template will process all the text nodes that are
> > children of elements with style attribute being equal
> > to 'it',
>
> This is an abbrevated verion of a template:
>
> <xsl:template match="name">
> <xsl:variable name="info" select="@flag"/>
> <xsl:variable name="link" select="@url"/>
> <a title="{$info}" href="{$link}"
> target="_blank"><xsl:apply-templates/></a>
Oh, great, that's how it really should be done.
> </xsl:template>
>
> It seems to work fine with your code.
As it should.
> > BUT, it will only work if you're not trying to do
> > anything with text nodes when you match the
> > corresponding elements.
>
> This I cannot follow, could you please give an example?
Well, consider the following example:
<xsl:template match="name">
<xsl:copy>
<xsl:value-of
select=
"
translate
(
.,
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
)
"/>
</xsl:copy>
</xsl:template>
If you processed your text nodes that way, obviously, my
solution wouldn't work, because templates would never be
applied to them. That's one of the reasons to stick to
template-based processing whenever you can.
> > And, of course, you'll have to add
> > <xsl:apply-templates select="text()"/> or somesuch
> > somewhere (or simply use the identity transformation).
>
> The simple <xsl:apply-templates/> seems to work in my
> case.
If select attribute is omitted, templates are applied to
all child::node()s, which includes all the text node
children.
> Are there any possible drawbacks, or specific situations
> where <xsl:apply-templates select="text()"/> should
> rather be used.
If you need to process text nodes only, you should use
text(). If you need to process all the children nodes,
<xsl:apply-templates/> should be used. In my example, I
used <xsl:apply-templates select="text()"/> for clarity's
sake.
--
Pavel Lepin