troubleshooting Question

Applying templates using XSLT on a simple XML

Avatar of Jammerules
Jammerules asked on
ProgrammingHTMLXML
8 Comments1 Solution296 ViewsLast Modified:
I am a noob to XML and XSLT, so pardon me for such a question. Here is what I am trying to do. I have an XML file like this:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="xsltfile_ex2.xslt"?>
<Profiles>
    <Profile>
      <Salutation>Mr. </Salutation>  
      <FirstName>Barack</FirstName>
      <LastName>Obama</LastName>
      <ID>123</ID>
    </Profile>
</Profiles>

And I have an XSLT file like this:

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
  <xsl:output method="html"/>

  <xsl:template match="/">
    <html>
      <body>
        <xsl:apply-templates select="Profiles/Profile"/>         
      </body>
    </html>
  </xsl:template>

  <xsl:template match="Profile"> 
      <tr>
          <xsl:apply-templates select="./FirstName"/>
      </tr>
  </xsl:template>

  <xsl:template match="FirstName">
    <tr bgcolor="red">
        <xsl:apply-templates select="./LastName"/>        
    </tr>
  </xsl:template>

  <xsl:template match="LastName">
    <tr bgcolor="red">
      <xsl:value-of select="./LastName"/>
    </tr>
  </xsl:template>
</xsl:stylesheet>
 

I am trying to get the Last Name from the XML. What is it that I am doing wrong? If someone also could please explain to me how the control flows in the above example (after correction), I'd appreciate that. Thanks!
ASKER CERTIFIED SOLUTION
mccarl
IT Business Systems Analyst / Software Developer
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros