Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 11th, 2009, 08: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.?
Reply With Quote
  #2 (permalink)  
Old May 11th, 2009, 09:27 AM
Friend of Wrox
Points: 6,525, Level: 34
Points: 6,525, Level: 34 Points: 6,525, Level: 34 Points: 6,525, Level: 34
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,221
Thanks: 0
Thanked 238 Times in 237 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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting fields, specific order from xml using xslt Jaipal XSLT 4 July 23rd, 2007 12:35 PM
how to populate a table with xml data in xslt miccipynewbie XSLT 6 May 28th, 2007 08: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



All times are GMT -4. The time now is 11:55 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.