This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

XSLT/XML  RSS feed

 
Veronica Damian
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!