XML Tutorial: Parsing XML with child elements that have the same name using XSLT/XSL



1. Problem Statement

I am wondering if there is a way to transfer over a parent element with all of its children elements that have the same element name using XSLT.

For example, if the original xml file is like this:
<parent>
<child>1</child>
<child>2</child>
<child>3</child>
</parent>



And I try to parse it with xsl using:

<xsl:for-each select="parent">
<xsl:value-of select="child"></xsl:value-of>
</xsl:for-each>


wanting something like this:

1

2

3



but I get this:

1



2. How to solve?


<xsl:for-each select="parent/child">
<xsl:value-of select="."/>
</xsl:for-each>


Then, will display as what you want:

1

2

3


credited to: http://stackoverflow.com/questions/6604209/parsing-xml-with-child-elements-that-have-the-same-name-using-xslt-xsl

Popular Posts

.

Sila Klik, Untuk  Menempah Web Profesional!
Facebook Page
Facebook Page
Back to Top