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 September 7th, 2006, 02:30 PM
Friend of Wrox
 
Join Date: Mar 2004
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.

 
Old September 7th, 2006, 02:51 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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





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





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