Help with transformation

J

Jeff Higgins

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>
 
J

Jeff Higgins

Jeff said:
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>
 
J

Jeff Higgins

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>
 
J

Jeff Higgins

Jeff Higgins wrote:>

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>
 

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,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top