Help with transformation

Discussion in 'XML' started by Jeff Higgins, May 11, 2006.

  1. Jeff Higgins

    Jeff Higgins Guest

    Hi,
    will someone show me how to write a transformation
    to obtain the desired output from the following input xml?

    Any help will be greatly appreciated.
    Thanks.
    Jeff Higgins

    Input xml:

    <chapter>
    <section>
    <section_header>Getting Started</section_header>
    <paragraph>This section covers the fundamental</paragraph>
    <section>
    <section_header>User Interface</section_header>
    <paragraph>This section provides information on</paragraph>
    <section>
    <section_header>Components of the UI</section_header>
    <paragraph>The main area of the screen is </paragraph>
    </section>
    <section>
    <section_header>Menus</section_header>
    <paragraph>The main menu</paragraph>
    </section>
    </section>
    </section>
    </chapter>

    Desired output:

    <toc>
    <entry>1 Getting Started</entry>
    <entry>1.1 User Interface</entry>
    <entry>1.1.1 Components of the UI</entry>
    <entry>1.1.2 Menus</entry>
    </toc>
     
    Jeff Higgins, May 11, 2006
    #1
    1. Advertising

  2. Jeff Higgins

    Jeff Higgins Guest

    Jeff Higgins wrote:
    > Hi,
    > will someone show me how to write a transformation
    > to obtain the desired output from the following input xml?
    >

    [snip]

    So far I have the following, which gives:

    <entry>Getting Started</entry>
    <entry>User Interface</entry>
    <entry>Componrnts of the UI</entry>
    <entry>Menus</entry>

    but I still need help wrapping the above with a <toc> tag,
    and inserting the section numbers.

    Thanks
    Jeff Higgins

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

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

    <xsl:template match="//section">
    <entry>
    <xsl:value-of select="section_header"/>
    </entry>
    <xsl:apply-templates />
    </xsl:template>

    </xsl:stylesheet>
     
    Jeff Higgins, May 11, 2006
    #2
    1. Advertising

  3. Jeff Higgins wrote:
    > but I still need help wrapping the above with a <toc> tag,


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

    would be one obvious solution...

    > and inserting the section numbers.


    You might want to look at the examples at
    http://www.dpawson.co.uk/xsl/sect2/N5758.html
     
    Joe Kesselman, May 11, 2006
    #3
  4. Jeff Higgins

    Jeff Higgins Guest

    Jeff Higgins wrote:>
    [snip]
    >
    > but I still need help wrapping the above with a <toc> tag,


    This fixes the toc tag:

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

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

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

    <xsl:template match="//section">
    <entry>
    <xsl:value-of select="section_header"/>
    </entry>
    <xsl:apply-templates />
    </xsl:template>

    </xsl:stylesheet>

    > and inserting the section numbers.
     
    Jeff Higgins, May 12, 2006
    #4
  5. Jeff Higgins

    Jeff Higgins Guest


    > Jeff Higgins wrote:>


    > [snip]


    This fixes inserting the section numbers.

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

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

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

    <xsl:template match="//section">
    <entry>
    <xsl:number level="multiple" count="section" format="1.1"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="section_header"/>
    </entry>
    <xsl:apply-templates />
    </xsl:template>

    </xsl:stylesheet>
     
    Jeff Higgins, May 12, 2006
    #5
    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. =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?=

    Help on XLS transformation ????

    =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?=, Feb 10, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,438
    =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?=
    Feb 10, 2006
  2. coincoin
    Replies:
    0
    Views:
    582
    coincoin
    Aug 5, 2003
  3. Mike Conmackie
    Replies:
    4
    Views:
    746
    Mike Conmackie
    Apr 29, 2004
  4. omegaman
    Replies:
    1
    Views:
    566
    omegaman
    Sep 21, 2004
  5. yannicklaclau
    Replies:
    2
    Views:
    535
    yannicklaclau
    Feb 28, 2005
Loading...

Share This Page