homepage Welcome to WebmasterWorld Guest from 54.226.93.128
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
Question about XSL stylesheet
robotsonic




msg:4108262
 2:06 pm on Apr 1, 2010 (gmt 0)

I'm trying to develop a generic stylesheet that will work with any XML document, regardless of the names of its nodes, but I'm not sure how to reference them .

For example, using the example from the W3C schools website,

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog">
<xsl:for-each select="cd">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

This style sheet specifies specific node names such as 'catalog', 'cd','title', 'artist, etc. What would you do if you just wanted it to output the nodes generically without the need to specify a name, so that the style sheet would work with all xml documents of the same format?

I tried using 'root' and 'firstChild', etc but it didn't seem to work, any ideas?

 

httpwebwitch




msg:4109297
 6:22 am on Apr 3, 2010 (gmt 0)

you'll need to sharpen your Axes [w3.org]

bizminder




msg:4111241
 7:46 am on Apr 7, 2010 (gmt 0)

I am interested to know what this Axes is about. I have been using a lot of HTML and XSL,but had not really thought about this.

httpwebwitch




msg:4111326
 11:53 am on Apr 7, 2010 (gmt 0)

Axes are plural of "axis" - a strange usage of the word, but it's the name of a device that lets an XPATH expression refer to a parent, ancestor, sibling, descendent-or-self, etc.

An axis is a selector that can find a node based on its relationship to the current node, regardless of its name or type. You can get the first child of a <book>, without knowing that it's a <chapter>.

Knowing XPATH is useful in all finds of XML parsing situations, not just in XSLT templates. If you are familiar with CSS selectors, XPATH has a lot in common with those.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved