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:
  #1  
Old August 17th, 2004, 12:22 PM
1ei1a 1ei1a is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 32 1ei1a User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 28 m 13 sec
Reputation Power: 5
Question select attributes regardless of node level

Hi,

I have an xml document as follows:

<navigation>
<navItem href="/mysite/Default.aspx" title="Home" />
<navItem href="/mysite/About.aspx" title="About">
<subItem href="/mySite/About/Main.aspx" title="Main" />
<subItem href="/mySite/About/Products.aspx" title="Products" />
</navItem>
<navItem href="/mysite/Contact.aspx" title="Contact">
<subItem href="/mySite/Contact/Address.aspx" title="Find us" />
</navItem>
</navigation>

As you can see, I have @HREF attributes that are at different node levels within my XML document. Is it possible to loop through all the href attributes within the document regardless of their level?
My xsl looks like this at the moment:

.
.
.
<xsl:for-each select="navItem/.">
<xsl:if test="@href=$href" >
.
.
.

However, this obviously only searches the @href attrributes on the navItem level.

Many thanks!

Reply With Quote
  #2  
Old August 17th, 2004, 02:59 PM
NotGoddess's Avatar
NotGoddess NotGoddess is offline
Kung-fu Kitty
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 350 NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 6 h 9 m 2 sec
Reputation Power: 10
Send a message via AIM to NotGoddess
Sample stylesheet to show selections (use w/ your xml file)
PHP Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" />

<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head><title>navtest</title></head>
<body>
Shows only navItem (with or without href)
<ul>
<xsl:for-each select="//navItem">
  <li><xsl:value-of select="@href"/></li>
</xsl:for-each>
</ul>

Show any element with an 'href' attribute.
  <ul> 
    <xsl:for-each select="//@href">
      <li><xsl:value-of select="."/></li>
    </xsl:for-each>
  </ul>
OR
  <ul>
    <xsl:for-each select="//*/@href">
      <li><xsl:value-of select="."/></li>
    </xsl:for-each>
  </ul>

Only elements with an href:
  <ul>
    <xsl:for-each select="//*[@href!='']">
      <li><xsl:value-of select="@title"/> -> <xsl:value-of select="@href"/></li>
    </xsl:for-each>
  </ul>

</body>
</html>
</xsl:template>
</xsl:stylesheet>

Reply With Quote
  #3  
Old August 18th, 2004, 05:04 AM
1ei1a 1ei1a is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 32 1ei1a User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 28 m 13 sec
Reputation Power: 5
Quote:
Originally Posted by NotGoddess
Sample stylesheet to show selections (use w/ your xml file)
PHP Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" />

<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head><title>navtest</title></head>
<body>
Shows only navItem (with or without href)
<ul>
<xsl:for-each select="//navItem">
  <li><xsl:value-of select="@href"/></li>
</xsl:for-each>
</ul>

Show any element with an 'href' attribute.
  <ul> 
    <xsl:for-each select="//@href">
      <li><xsl:value-of select="."/></li>
    </xsl:for-each>
  </ul>
OR
  <ul>
    <xsl:for-each select="//*/@href">
      <li><xsl:value-of select="."/></li>
    </xsl:for-each>
  </ul>

Only elements with an href:
  <ul>
    <xsl:for-each select="//*[@href!='']">
      <li><xsl:value-of select="@title"/> -> <xsl:value-of select="@href"/></li>
    </xsl:for-each>
  </ul>

</body>
</html>
</xsl:template>
</xsl:stylesheet>


Thank you NotGoddess! Exactly what I was looking for!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > select attributes regardless of node level


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 1 hosted by Hostway
Stay green...Green IT