SunQuest
           XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old August 7th, 2003, 06:24 AM
hade hade is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2001
Posts: 178 hade User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 47 m 47 sec
Reputation Power: 7
displaying all attributes

Hi

I have recently started experimenting with xpath/xslt. I have a problem displaying all the attributes from a xml file

Here is my xml file

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="employee.xsl"?>
<source>

<AAA pos="start" id="a1">
<BBB id="b1"/>
<BBB/>
</AAA>
<AAA id="a2">
<BBB id="b3"/>
<BBB dsids="b4" dfhk="b6"/>
<CCC id="c1">
<DDD id="d1"/>
</CCC>
<BBB idt="b5">
<CCC id="c2"/>
</BBB>
</AAA>
</source>


My xslt file looks like this

<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">

<xsl:for-each select="//*[@*]">
<DIV style="color:red">
<xsl:value-of select="name()"/>
<xsl:text> </xsl:text>
<xsl:value-of select="name(@*)"/>
<xsl:text> = </xsl:text>
<xsl:value-of select="@*"/>
</DIV>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

The output is
AAA pos = start
BBB id = b1
AAA id = a2
BBB id = b3
BBB dsids = b4
CCC id = c1
DDD id = d1
BBB idt = b5
CCC id = c2

Some elements (AAA,BBB) have 2 attributes but in the output only the first attribute is displayed. How can I display both the attributes.

Last edited by hade : August 7th, 2003 at 06:26 AM.

Reply With Quote
  #2  
Old August 7th, 2003, 07:03 AM
Wizard2003's Avatar
Wizard2003 Wizard2003 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 206 Wizard2003 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 29 m 24 sec
Reputation Power: 6
Try this:
Code:
<xsl:for-each select="//*">
  <xsl:value-of select="name()"><xsl:text> </xsl:text>
  <xsl:for-each select="@*">
    <xsl:value-of select="name()"><xsl:text> </xsl:text><xsl:value-of select=".">
  </xsl:for-each>
</xsl:for-each>

Please let me know if it works...

Reply With Quote
  #3  
Old August 7th, 2003, 07:27 AM
hade hade is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2001
Posts: 178 hade User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 47 m 47 sec
Reputation Power: 7
Thanks a lot. It works fine

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > displaying all attributes


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway