File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes XSLT/XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSLT/XML" Watch "XSLT/XML" New topic


Veronica Damian
Ranch Hand

Joined: Feb 04, 2006
Posts: 61
if I have the following xml:

<addresses> <-- root
<name>Joe Doe</name>
<add>69 Linden Lane</add>
<add2>Apt. 3A</add2>

then in xslt stylesheet:

<xsl:template match="/">

<tr><td>name:</td><td><xsl:value-of select="addresses/person/name"/></td></tr>
<tr><td>add:</td><td><xsl:value-of select="addresses/person/add"/></td></tr>

why do I have to include 'addresses' in value-of tag? I mean doesn't this

<xsl:template match="/">

represent the root of xml (namely 'addresses' node)??

so it seems to me this should work..

<tr><td>add:</td><td><xsl:value-of select="person/add"/></td></tr>

since current node is 'addresses'.. but it doesn't..

thank you..

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

No, "/" matches the document root. This is a sorta-fictitious node that is the parent of the document element, which in your example is the <address> element.
Ravi Shankar

Joined: Apr 07, 2003
Posts: 26
Instead of <xsl:template match="/"> if you have written as <xsl:template match="addresses"> then the xsl:value-of need not specify the 'addresses' element
Pat Flickner
Ranch Hand

Joined: Nov 17, 2003
Posts: 173
Yes, but as I discovered, sometimes setting the root doesn't set the root. I couldn't get my page to display until I created a template for <reports> even though I had set the base template. Did I hit something weird? Or is it just me (which is always likely as my code seems to process in an alternate universe where normal things end up abnormal), or is it old xml transform I'm using:

I agree. Here's the link:
subject: XSLT/XML
It's not a secret anymore!