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

M

Matt

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!!
 
W

William Park

Matt said:
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?
 
B

Ben Edgington

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 #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"
xmlns:xsl="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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top