Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 11th, 2009, 07:57 AM
Registered User
 
Join Date: May 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT for displaying XML data in list order

Hi all,
i have the XML like this:
<Root>
<MainHeading>TESTING XSLT</MainHeading>
<boby>
<id>1</id>
<heading>Name</heading>
<detail>This is name of user</detail>
</body>
<boby>
<id>2</id>
<heading>Address</heading>
<detail>This is address of user</detail>
</body>
<boby>
<id>3</id>
<heading>Phones</heading>
<detail>
<inner>Home </inner>
<inner>Office</inner>
<inner>Personnel</inner>
</detail>
</body>
</Root>

how can i write XSLT for this xml to that in the following manner

TESTING XSLT
Name
  • This is name of user
Address
  • This is address of user
Phones
  • Home
  • Office
  • Personnel
Please show me the way, To get the solution whether
i have to change the xml or not.?
 
Old May 11th, 2009, 08:27 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Assuming you want to transform your XML to HTML with heading (h1, h2) and list (ul, li) elements then here is a stylesheet:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  
  <xsl:output method="html" indent="yes"/>
  <xsl:strip-space elements="*"/>
  
  <xsl:template match="/Root">
    <html>
      <head>
        <title>Example</title>
      </head>
      <body>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>
  
  <xsl:template match="MainHeading">
    <h1>
      <xsl:apply-templates/>
    </h1>
  </xsl:template>
  
  <xsl:template match="body">
    <div>
      <xsl:apply-templates select="heading | detail"/>
    </div>
  </xsl:template>
  
  <xsl:template match="body/heading">
    <h2>
      <xsl:apply-templates/>
    </h2>
  </xsl:template>
  
  <xsl:template match="body/detail">
    <ul>
      <xsl:apply-templates/>
    </ul>
  </xsl:template>
  
  <xsl:template match="body/detail//text()">
    <li>
      <xsl:value-of select="."/>
    </li>
  </xsl:template>

</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting fields, specific order from xml using xslt Jaipal XSLT 4 July 23rd, 2007 11:35 AM
how to populate a table with xml data in xslt miccipynewbie XSLT 6 May 28th, 2007 07:29 AM
How to Query XML Data from XSLT Form kwilliams XSLT 1 December 3rd, 2005 06:14 AM
using 2 sets of xml data from 1 xslt davepass XSLT 2 April 1st, 2005 06:31 PM
Displaying time in chronological order mg1966 Classic ASP Databases 3 January 24th, 2005 02:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.