Is it possible with XSLT????

Discussion in 'XML' started by Luke Olek, Oct 2, 2003.

  1. Luke Olek

    Luke Olek Guest

    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!
    Luke Olek, Oct 2, 2003
    #1
    1. Advertising

  2. In article <>,
    Luke Olek <> wrote:

    % 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.

    --

    Patrick TJ McPhee
    East York Canada
    Patrick TJ McPhee, Oct 3, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stylus Studio
    Replies:
    0
    Views:
    622
    Stylus Studio
    Aug 3, 2004
  2. Benjamin Hillsley
    Replies:
    3
    Views:
    1,651
    Dimitre Novatchev
    Sep 25, 2003
  3. ted
    Replies:
    1
    Views:
    607
    Laurens
    Jan 26, 2004
  4. Replies:
    2
    Views:
    701
    Henry S. Thompson
    Oct 19, 2005
  5. Replies:
    4
    Views:
    648
Loading...

Share This Page