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

RE: XSL nested tag help

Subject: RE: XSL nested tag help
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Mon, 7 Oct 2002 17:45:05 -0400
nested div tags under
[Mani Malarvannan ]

> For my XSL nested tag question some of you responded with a solution 
> of using text(), but that solution is not working. When I tried with 
> the solution, the text under "Target" tag is printing at the end 
> of text under "Main" ie,
> 
> <h1>This is a first test message it is important<h1>
> <h2> and <h2>
> 
> But I need the output to be 
> <h1>This is a first test message <h2> and </h2> it is important</h1>
> 
> 

I have not been following this thread closely, but it seems to me that
you just want to replace  "Main" elements with  "h1" elements, and
"Target" elements with "h2".  The easest way to do this is to is using
an identity transform to copy everything you do not want changed.  I
illustrate this below, but first there is another point.

Your output looks like html, but it is not actually valid html, because
header elements may not nest inside other header elements according to
the html Recommendation.  So even if current browsers may display it the
way you intend, I suggest you find another way to represent your
results.  You can use css to produce the appearance you want.  Of
course, this is getting off-topic for the list.  I would suggest (then I
will leave this topic)

<div class='Main'>This is a first test message  <span
class='Target'>and</span> it is important</div>

This approach preserves the semantics of your source and does not abuse
HTML just to get a certain appearance.

Here is the xslt example (it ignores comments and processing
instructions, but you can easily add them in if you need to):

<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

<xsl:template match='Main'>
	<h1><xsl:apply-templates/></h1>
</xsl:template>

<xsl:template match='Target'>
	<h2><xsl:apply-templates/></h2>
</xsl:template>

<!-- Identity transformation template -->			
<xsl:template match='*|@*'>
	<xsl:copy>
		<xsl:apply-templates select="@* | * "/>
	</xsl:copy>
</xsl:template>
</xsl:stylesheet>

Cheers,

Tom P

 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.