Re: [xsl] XSL nested tag help

Subject: Re: [xsl] XSL nested tag help
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Mon, 07 Oct 2002 23:59:45 +0200
Hello Tom,

the first time he wrote <h1>..</h1><h2>..</h2><h1>..</h1>, so that's not the problem. Then at least 3 solutions (or better said thrice the same solution) were posted, which looked exactly as you have it. Now is the problem, that the output does not look like he expect it.



Passin, Tom wrote:
[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="";>

<xsl:template match="/">

<xsl:template match='Main'>

<xsl:template match='Target'>

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


Tom P

XSL-List info and archive:

Current Thread