Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Possible to traverse the children of an element without specifying child element names?

Reply
Thread Tools

Possible to traverse the children of an element without specifying child element names?

 
 
Matt
Guest
Posts: n/a
 
      10-12-2004
Is it possible to traverse the values of children of an element, and
no need to specify
the children's element names in XSLT element?

The XML file can be

<bio>
<skills>
<languages>
<language>XML</language>
<language>Java</language>
</languages>
<databases>
<database>Oracle</database>
</databases>
</skills>
</bio>

Approach #1: This will just append all data in a sequence of strings,
not good
<UL>
<xsl:for-each select="/bio/skills">
<LI><xsl:value-of select="."/></LI>
</xsl:for-each>
</UL>

Approach #2: correct approach, but it's tedious to specify all element
names that
need to traverse
<UL>
<xsl:for-each select="/resume/skills">
<xsl:for-each select="languages/language">
<LI><xsl:value-of select="."/></LI>
</xsl:for-each>
<xsl:for-each select="databases/database">
<LI><xsl:value-of select="."/></LI>
</xsl:for-each>
</xsl:for-each>
</UL>

any ideas? please advise. thanks!!
 
Reply With Quote
 
 
 
 
William Park
Guest
Posts: n/a
 
      10-12-2004
Matt <(E-Mail Removed)> wrote:
> Is it possible to traverse the values of children of an element, and
> no need to specify
> the children's element names in XSLT element?
>
> The XML file can be
>
> <bio>
> <skills>
> <languages>
> <language>XML</language>
> <language>Java</language>
> </languages>
> <databases>
> <database>Oracle</database>
> </databases>
> </skills>
> </bio>


Above is input. What output do you want?

--
William Park <(E-Mail Removed)>
Open Geometry Consulting, Toronto, Canada
 
Reply With Quote
 
 
 
 
Ben Edgington
Guest
Posts: n/a
 
      10-12-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Matt) writes:

> Is it possible to traverse the values of children of an element, and
> no need to specify
> the children's element names in XSLT element?
>
> The XML file can be
>
> <bio>
> <skills>
> <languages>
> <language>XML</language>
> <language>Java</language>
> </languages>
> <databases>
> <database>Oracle</database>
> </databases>
> </skills>
> </bio>


<snip>

> Approach #2: correct approach, but it's tedious to specify all element
> names that
> need to traverse
> <UL>
> <xsl:for-each select="/resume/skills">
> <xsl:for-each select="languages/language">
> <LI><xsl:value-of select="."/></LI>
> </xsl:for-each>
> <xsl:for-each select="databases/database">
> <LI><xsl:value-of select="."/></LI>
> </xsl:for-each>
> </xsl:for-each>
> </UL>
>
> any ideas? please advise. thanks!!


Does this help?

<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<ul>
<xsl:for-each select="bio/skills/*/*">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>
</xsl:template>

</xsl:stylesheet>

--
Ben Edgington
Mail to the address above is discarded.
Mail to ben at that address might be read.
http://www.edginet.org/
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirect after child loads, without sending data back from child Jason Carlton Javascript 4 12-16-2009 04:56 PM
lxml: traverse xml tree and retrieve element based on an attribute byron Python 5 05-30-2009 08:00 AM
element.children.length v/s element.childNodes.length okey Javascript 2 05-24-2009 04:36 PM
Specifying element classnames using XJC JAXB ant task Robert Reeves Java 0 11-11-2005 03:04 AM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments