Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML for-each a eleemtnt and get value of it 1

Status
Not open for further replies.

JuanKerr

IS-IT--Management
Mar 15, 2005
2
GB
ive got some xml:
----------------------------
<section id="commentary">
<section id="comment">test1</section>
<section id="comment">test2</section>
<section id="comment">test3</section>
</section>
----------------------------

applying this xsl:
----------------------------
<xsl:for-each select="section[@id='commentary']/section">
<xsl:value-of select="section[@id='comment']"/>
(found) <br/>
</xsl:for-each>
----------------------------

it just gives me
------------------------------
(found)
(found)
(found)
------------------------------
so the "<xsl:value-of select="section[@id='comment']"/>" isnt working from within the for each


with this xsl
------------------------------
<xsl:for-each select="section[@id='commentary']">
<xsl:value-of select="section"/>
(found) <br/>
</xsl:for-each>
------------------------------

it only gives me
-------------------------------
test1 (found)
-------------------------------
so im getting the value but its only getting the first occourance.

..So how do i loop all the <section id="comment"> and get all values of <section id="comment">..
i think its because the attributes are all the same but i cant do much about that since its the way i get it sent.

cheers for your time.
 
Your context is already section/section from the for-each. So putting a value-of section is the same as saying section/section/section, which doesn't exist. Use:
Code:
<xsl:for-each select="section[@id='commentary']/section[@id='comment']"/">
  <xsl:value-of select="."/>
  (found)  <br/>
</xsl:for-each>

 
Wow cheers.. its so simple and yet so brilliant.. "."
Thanks! I was trying "../" and "./" and calling the whole thing again from root but never thought of "."!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top