?
Solved

XSLT with nested Elements

Posted on 2011-03-09
1
Medium Priority
?
406 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 2000 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

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

762 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