[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

Subject: RE: apply-templates and XHTML's <p> tag
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Mon, 24 Mar 2003 21:15:45 -0000
xslt p tag
The standard design pattern is to define a template rule for each
element, and in each such template rule, call apply-templates to process
the children. That way you do a depth-first traversal of the entire
tree, processing each element as it is encountered. If the source format
is similar to the result format, you define an identity template rule as
the default rule, so things just get copied across.

For example

<xsl:template match="bold">
<b><xsl:apply-templates/></b>
</xsl:template>

processes the <bold> element, replacing it with a <b> element, and
calling apply-templates to process all its children (text nodes and
element nodes) with their appropriate rules.

You don't ever need to use xsl:value-of, and normally you shouldn't use
it except when processing a node that you know has no children.

Michael Kay


> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Gan Uesli Starling
> Sent: 24 March 2003 18:00
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  apply-templates and XHTML's <p> tag
> 
> 
> This would be none too hard in Perl. But I am stumped
> for it in XSLT. When one does...
> 
> <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.
> 
> Cool would be to split <p> into a sequence of <foo>
> tags with the <b> and <i> as attributes for some,
> not on others.
> 
> Can someone point me at a tutorial or how-to which
> illustrates an XSLT-ish method for dealing sequentially
> with a mixed bunch of text and tags?
> 
> Thanks,
> 
> Gan
> -- 
> 
>   Mistera Sturno - Rarest Extinct Bird
> 
>   <(+)__       Gan Uesli Starling
>    ((__/)=-    Kalamazoo, MI, USA
>     `||`
>      ++        http://starling.us
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.