Results 1 to 6 of 6

Thread: Looping throught XML childnodes without JavaScript

  1. #1
    Join Date
    Apr 2010

    Looping throught XML childnodes without JavaScript

    Hi there

    A quick one (I think).
    I am kind of new to XML and I'm kind of stuck on something that may be trivial to most of you.
    I have something like this:

    eg 1:
    <table_of_content>List of topics:</table_of_content>
    <title>title one</title>
    <title>title two</title>
    <title>title three</title>
    <title>title four</title>
    How will I display on the site page something like
    List of topics:
    1. title one
    2. title two
    3. title three
    4. title four

    I mean how would I do something like looping through the elements (what I am mostly interested is displaying the values of elements with the same name, i.e. title,title,title,etc) but using only XML, XSD, XSLT/XPath, without using JavaScript or Pearl or similar?

    eg 2:

    <name>John Smith</name>
    <name>Joe Smith</name>
    <name>Bob Smith</name>
    <name>Black Smith</name>
    <name>Lock Smith</name>

    Here, how do you display on page the values of all occurances of name and email elements, as in:

    John Smith / john.smith@mail.com
    Joe Smith / joe.smith@mail.com
    Bob Smith / bob.smith@mail.com


    In my naivity and misunderstanding of how XML and XSLT/XPath works I thought something like
    <xsl:for-each select="club_members">
    <xsl:value-of select="name"/>
    <xsl:value-of select="email"/>
    would actually loop through the children of some parent element.

    Would you,guys, be so kind and put toghether a tiny combination of the three (XML, XSLT/XPath, XSD) that might show me how these work toghegher towards the result I mentioned before? But, again, is there any way this can be done without using JS or other prog. languages?

    Cheers, folks!


  2. #2
    Join Date
    Apr 2010
    Slow down, boys, slow down! One at a time, don't push! There is room for every one, no need to push in order to jump and help. Slow down!


  3. #3
    Join Date
    Aug 2006
    I'm not sure your xml syntax on the name one was good, so I changed it

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="test.xsl"?>
    <name>John Smith</name>
    <name>Joe Smith</name>
    <name>Bob Smith</name>
    <name>Black Smith</name>
    <name>Lock Smith</name>
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>Untitled 1</title>
    <p><xsl:for-each select="club_members/member">
    	<xsl:value-of select="name"/>
    	<xsl:value-of select="email"/>
    	<br />
    Save these off, and view test.xml


  4. #4
    Join Date
    Apr 2010
    Thanks a lot, Dave, for your reply!
    Some time ago I received an assignment that stated the code structure should not be modified but to work and find a solution to display on the values from the code as is. And the code did look something like both the one displayed on both e.g.1 and e.g.2 in my message. It confused de heck out of me. I spent some time on some of the classic tutorials on the net (things like w3schools, tizag, etc) but I just can not find a solution. I did write something like the following which displayed ok in Internet Explorer but not in Firefox:

    <xsl:for-each select="book/title">
    <li><xsl:value-of select="list/child::node()"/></li>

    <li><xsl:value-of select="list/child::node()/following-sibling::node()"/></li>

    <li><xsl:value-of select="list/child::node()/following-sibling::node()
    <li><xsl:value-of select="list/child::node()/following-sibling::node()
    /following-sibling::node()"/></li> </ul>


    And for the second:

    <th>Club Member</th>
    <xsl:for-each select="club_members/member">
    <td><xsl:value-of select="node()"/></td>
    <td><xsl:value-of select="following-sibling::node()"/></td>


    But these solutions really look odd to me.

    Thanks again for takin time to help!!


  5. #5
    Join Date
    Aug 2006
    They look odd to me too. But I should say that I tried to appreciate XSLT, but realistically I pretty much hate it. I find it far easier to parse and display XML with PHP's SimpleXML interface, and that's what I do*.


    * as a hobby developer. I am not doing this for a living where it might somehow actually matter.

  6. #6
    Join Date
    Apr 2010
    Cheers, Dave. I'll keep on playing with it maybe I bump into something that will do it. I really wish I could use some third party solution to this 'coz I'm getting tired of it now.


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.28572 seconds
  • Memory Usage 2,899KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (71):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates