Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
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 Search this Thread Display Modes
  #1 (permalink)  
Old September 7th, 2006, 02:30 PM
Friend of Wrox
 
Join Date: Mar 2004
Location: Ottawa, , Canada.
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default reading data

Hi,

Still trying to grasp xsl, and having a hard time understand how I can go through this build... Now I find the Attribute that I'm looking for by doing this:

<xsl:template match="/env">
   <xsl:for-each select="Attribute[Type='Email_Details']">
  ->> stuff goes here...
   <xsl:for-each select"
</xsl:template>

but how can I iterate through the 2 sub Attributes of Value, and display that information?

<env>
   <Attribute>
      <Type>Email_Details</Type>
         <Value>
            <Attribute>
               <Type>Account A</Type>
               <Value>
                  <Attribute>
                     <Type>UserName</Type>
                     <Value>user A</Value>
                  </Attribute>
                  <Attribute>
                     <Type>SMTPServer</Type>
                     <Value>server A</Value>
                  </Attribute>
               </Value>
            </Attribute>
            <Attribute>
               <Type>Account B</Type>
               <Value>
                  <Attribute>
                     <Type>UserName</Type>
                     <Value>user B</Value>
                  </Attribute>
                  <Attribute>
                     <Type>SMTPServer</Type>
                     <Value>server B</Value>
                  </Attribute>
               </Value>
            </Attribute>
     </Value>
   </Attribute>
</env>

Thank you in advance.

Reply With Quote
  #2 (permalink)  
Old September 7th, 2006, 02:51 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You haven't made it clear quite how flexible the input structure is, or what kind of output you want. I would personally be very inclined to start by transforming this to a more straightforward XML representation:

<env>
  <Email_Details>
    <Account code="A">
       <UserName>User A</UserName>
       <SMPTServer>Server A</SMTPServer>
    <Account>
    <Account code="B">
       <UserName>User B</UserName>
       <SMPTServer>Server B</SMTPServer>
    <Account>
  </Email_Details>
</env>

and then everything would start to seem much simpler.

However, whatever the output you're aiming for, recursive structures are best dealt with by a stylesheet that does recursive descent using apply-templates. Just write a rule for each kind of element, and in that rule do what you need to do with that element, then call apply-templates to process its children. I can't tell you what these rules should look like (or even how many there should be - it's not clear whether attributes at different levels are processed the same way) without knowing your desired output.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Reading data from ms sql RAGHAVENDRAN C# 3 November 26th, 2007 05:26 AM
problem in reading excel data premnaath ASP.NET 2.0 Professional 5 October 22nd, 2007 10:14 AM
reading data from a memory scanner stealthdevil VB How-To 0 October 10th, 2006 08:43 AM
Reading Data From SQL Ridouan VB.NET 2002/2003 Basics 2 January 31st, 2005 05:43 PM
Reading data from database... Thomas82 Classic ASP Databases 3 February 25th, 2004 03:58 PM



All times are GMT -4. The time now is 01:36 AM.


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