A. Sac
A. Sac

Reputation: 11

XSLT not displaying

I am new to XML - XSLT transformation. I have the following XML file and the corresponding XSLT file but for some reason, it does not display anything pass the h2, which is an HTML. Any help will be great!

I have checked the namespace to make sure it matches the XML document, and I also tried running code on the W3 site as well.

Both files are below:

XML

<?xml version="1.0" encoding="UTF-8"?>
<alphabafictional_resume 
    xmlns="https://swe.umbc.edu/~asacko1/xs"
    xmlns:xsl="http://www.w3.org/2001/XMLSchema-instance"> 

    <objective>
        <obj_header>Objective</obj_header>
        <obj_body>Adaptable Data Analyst skilled in recording, interpreting and analyzing data in a fast-paced environment. Advanced proficiency in all aspects of Excel. Experienced in preparing detailed documents and reports while managing complex internal and external data analysis responsibilities.</obj_body>
    </objective>
    <core_qualifications>
        <qual_header>Core Qualifications</qual_header>
        <qual_list>
            <qual>Data and statistical analysis</qual>
            <qual>PC/Mac SAS and MS Excel proficiency</qual>
            <qual>Report generation</qual>
            <qual>Time management</qual>
            <qual>Project management</qual>
            <qual>Interpersonal communication</qual>
        </qual_list>
    </core_qualifications>
    <professional_experience>
        <experience>
            <exp_header>
                <job_title>Data Analyst</job_title>
                <time_on_job>
                    <start_date>9/1/2012</start_date>
                    <end_date>Present</end_date>
                </time_on_job>
                <employer_name>New Parkland Corporation</employer_name>
                <employment_location>
                    <emp_loc_city>New Parkland</emp_loc_city>
                    <emp_loc_2ltr_state>CA</emp_loc_2ltr_state>
                </employment_location>
            </exp_header>
            <exp_body>
                <exp_performance_list>
                    <perf>Interpret data from primary and secondary sources using statistical techniques and provide ongoing reports.</perf>
                    <perf>Compile and validate data; reinforce and maintain compliance with corporate standards.</perf>
                    <perf>Develop and initiate more efficient data collection procedures.</perf>
                    <perf>Working with managing leadership to prioritize business and information requirements.</perf>
                </exp_performance_list>
            </exp_body>
        </experience>   
        <experience>
            <exp_header>
                <job_title>Data Analyst</job_title>
                <time_on_job>
                    <start_date>6/1/2011</start_date>
                    <end_date>5/1/2012</end_date>
                </time_on_job>
                <employer_name>Lake City Industries</employer_name>
                <employment_location>
                    <emp_loc_city>Lake City</emp_loc_city>
                    <emp_loc_2ltr_state>CA</emp_loc_2ltr_state>
                </employment_location>
            </exp_header>
            <exp_body>
                <exp_performance_list>
                    <perf>Extracted, compiled and tracked data, and analyzed data to generate reports.</perf>
                    <perf>Worked with other team members to complete special projects and achieve project deadlines.</perf>
                    <perf>Developed optimized data collection and qualifying procedures.</perf>
                    <perf>Leveraged analytical tools to develop efficient system operations.</perf>
                </exp_performance_list>
            </exp_body>
        </experience>   
        <experience>
            <exp_header>
                <job_title>Data Analyst</job_title>
                <time_on_job>
                    <start_date>7/1/2010 </start_date>
                    <end_date>2/1/2011</end_date>
                </time_on_job>
                <employer_name>New Parkland Data Research Center</employer_name>
                <employment_location>
                    <emp_loc_city>New Parkland</emp_loc_city>
                    <emp_loc_2ltr_state>CA</emp_loc_2ltr_state>
                </employment_location>
            </exp_header>
            <exp_body>
                <exp_performance_list>
                    <perf_1>Performed daily data queries and prepared reports on daily, weekly, monthly, and quarterly basis</perf_1>
                    <perf_2>Used advanced Excel functions to generate spreadsheets and pivot tables</perf_2>
                </exp_performance_list>
            </exp_body>
        </experience>   
    </professional_experience>
    <education>
        <edu_header>Education</edu_header>
        <edu_body>
            <edu_list>
                <edu>
                    <edu_degree>Bachelor of Science</edu_degree>
                    <edu_major>Computer Science</edu_major>
                    <edu_school>
                        <edu_sch_name>New Parkland Business College</edu_sch_name>
                        <edu_sch_city>New Parkland</edu_sch_city>
                        <edu_sch_2ltr_state>CA</edu_sch_2ltr_state>
                        <edu_sch_grad>2014</edu_sch_grad>
                    </edu_school>
                </edu>
                <edu>
                    <edu_degree>Masters of Science</edu_degree>
                    <edu_major>Finance</edu_major>
                    <edu_school>
                        <edu_sch_name>University of California</edu_sch_name>
                        <edu_sch_city>New Parkland</edu_sch_city>
                        <edu_sch_2ltr_state>CA</edu_sch_2ltr_state>
                        <edu_sch_grad>2010</edu_sch_grad>
                    </edu_school>
                </edu>      
            </edu_list>
        </edu_body>
    </education>
</alphabafictional_resume>

XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
    <xsl:template match="/">
        <html>
            <body>
                <h2>Alphaba Resume - Long version</h2>
                <xsl:for-each select="alphabafictional_resume/objective">
                    <h2><xsl:value-of select="objective"/></h2>
                </xsl:for-each>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

Upvotes: 1

Views: 77

Answers (3)

Tim C
Tim C

Reputation: 70608

You mention that you have "checked the namespace to make sure it matches the XML document", but there is no reference at all to the namespace "https://swe.umbc.edu/~asacko1/xs" in your XSLT.

In your XML, "https://swe.umbc.edu/~asacko1/xs" is the default namespace. In XSLT 1.0, the way to handle these is to declare it with a namespace prefix, and use that prefix throughout the XSLT.

Try this XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:swe="https://swe.umbc.edu/~asacko1/xs">
<xsl:output method="html"/>
    <xsl:template match="/">
        <html>
            <body>
                <h2>Alphaba Resume - Long version</h2>
                <xsl:for-each select="swe:alphabafictional_resume/swe:objective">
                    <h2><xsl:value-of select="swe:obj_body"/></h2>
                </xsl:for-each>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

Note that the choice of prefix here (swe) is arbitrary. It could be anything, just as long as the namespace URI matches.

If you could use XSLT, things are slightly simpler when it comes to default namespaces, as you could use xpath-default-namespace instead, and not have to worry about adding a prefix:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xpath-default-namespace="https://swe.umbc.edu/~asacko1/xs">
<xsl:output method="html"/>
    <xsl:template match="/">
        <html>
            <body>
                <h2>Alphaba Resume - Long version</h2>
                <xsl:for-each select="alphabafictional_resume/objective">
                    <h2><xsl:value-of select="obj_body"/></h2>
                </xsl:for-each>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

Upvotes: 1

Michael Shopsin
Michael Shopsin

Reputation: 2138

My XSL will take care of converting the output into text for the <h2> tags. The XSL is more flexible in case someone embeds an objective somewhere in the resume that you didn't expect.

  <xsl:for-each select="//*[name()='obj_body']">
      <h2><xsl:value-of select="."/></h2>
  </xsl:for-each>

I use name() because the namespace isn't well defined so obj_body needs to be evaluated as a string.

Upvotes: 0

Flynn1179
Flynn1179

Reputation: 12075

You're iterating through objective elements, and trying to output the value of another objective element within each, but there aren't any. Should you be doing

<xsl:value-of select="obj_body"/>

instead?

Upvotes: 0

Related Questions