This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSLT/XML" Watch "XSLT/XML" New topic
Author

XSLT/XML

Veronica Damian
Ranch Hand

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

<addresses> <-- root
<person>
<name>Joe Doe</name>
<add>69 Linden Lane</add>
<add2>Apt. 3A</add2>
<city>Boston</city>
<state>MA</state>
<zip>02093</zip>
<phone>617-555-9394</phone>
<email>joe@yahoo.com</email>
</person>
</addresses>


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>
etc..

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..

-v
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18715
    
    8

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
Greenhorn

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: http://aspose.com/file-tools
 
subject: XSLT/XML