RE: [xsl] apply-templates and XHTML's <p> tag

Subject: RE: [xsl] apply-templates and XHTML's <p> tag
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Mon, 24 Mar 2003 14:50:52 -0500
[Gan Uesli Starling]
> <xsl:apply-templates select="foo"/>
> 
> ...XSLT seeks out and does all the <foo> tags
> and inflicts the foo template to them. I get that.
> 
> But when parsing an XHTML <p> tag, it may
> have text mish-mashed in and between <b> and <i>
> and <span> tags...in no fixed order.
> 
> I will lose all the style stuff if I just do...
> 
> <xsl:template match="p">
>    <xsl:value-of select="."/>
> </xsl:template>
> 
> ...as the <b>, <i> and <span> will go bye-bye with
> all their text siphoned out from them, yes? I don't
> want that, obviously.

If you want to get just the text out of mixed content like this, you can
use

<xsl:template match='p'>
	<xsl:apply-templates select='*| text()'/>==<br/>
</xsl:template>

<xsl:template match="*| text()"> 
	<xsl:value-of select='.'/>	
</xsl:template> 

(I put in the "==<br/>" just to clearly show the break between multiple
p elements).  This picks up the text content of nested elements inside
the "p" element.

If you simply want to copy the "p" with all its nested elements, just
use copy-of.  If you want to change some of the nested element names (or
just keep the text) you can use some variation of the identity
transform.  The details will depend onjust what you want to do.

Cheers,

Tom P

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


Current Thread