Is it possible with XSLT????

L

Luke Olek

How to transform:
<html>
<h1>Title</h1>
<h2>Header1</h2>
Content
<h3>Subeader1</h3>
Subcontent
</html>

to:
<newsletter>
<title>Title</title>
<section header="Header1">
Content
<subsection header="Subheader1">
Subcontent
</subsection>
</section>
</newsletter>

Any help appreciated!
 
P

Patrick TJ McPhee

% How to transform:
% <html>
% <h1>Title</h1>
% <h2>Header1</h2>
% Content
% <h3>Subeader1</h3>
% Subcontent
% </html>

You need templates to match each of the tags you want to change.
Here's one for html:
<xsl:template match="html">
<newsletter>
<xsl:apply-templates>
</newsletter>
</xsl:template>

the one for title will be similar. For the section headers,
you can do essentially the same thing. To get a value into the
attribute, use an attribute value template:

<xsl:template match="h1">
<section header="{text()}">
<xsl:apply-templates>
</section>
</xsl:template>

to copy the content,

<xsl:template match="node()|@*">
<copy>
<xsl:apply-templates select="node()|@*">
</copy>
</xsl:template>

once you get to the lowest-level heading, you can fast-path the copy
by using <xsl:copy-of select="node()"/> instead of xsl:apply-templates.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top