Solved

XSLT with nested Elements

Posted on 2011-03-09
1
405 Views
Last Modified: 2013-11-18



Hi,

I would like to number child Elements in the below XML using XSLT. How can we achieve this. basically there can be any number of child Elements nested.

Output :

1 child
1.1 child
1.1.1 child

1 child
1.1.

1 child
1.1 child










Input xml

<?xml version="1.0" encoding="utf-8"?>
<root>
  <child>
    <child>
      <child>
       
      </child>
     
    </child>    
 
  </child>

  <child>
    <child>

    </child>
  </child>

  <child>
    <child>
     
     
    </child>
   
  </child>
 
 
</root>



0
Comment
Question by:Techsavy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 35093199

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:output indent="yes"/>
    <xsl:template match="root">
        <html>
            <body>
                <xsl:apply-templates select="child">
                    <xsl:with-param name="number" select="'1. '"/>
                </xsl:apply-templates>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="child">
        <xsl:param name="number"/>
        <p>
            <xsl:value-of select="$number"/>
            <xsl:value-of select="name()"/>
        </p>
        <xsl:apply-templates select="child">
            <xsl:with-param name="number" select="concat('1.', $number)"/>
        </xsl:apply-templates>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question