XSLT not displaying



我是 XML - XSLT 转换的新手。我有以下XML文件和相应的XSLT文件,但由于某种原因,它没有显示任何通过h2的内容,这是一个HTML。任何帮助都会很棒!

我已经检查了命名空间以确保它与 XML 文档匹配,并且我还尝试在 W3 站点上运行代码。

两个文件如下:

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

您提到您已经"检查了命名空间以确保它与 XML 文档匹配",但 XSLT 中根本没有对命名空间"https://swe.umbc.edu/~asacko1/xs"的引用。

在 XML 中,"https://swe.umbc.edu/~asacko1/xs"是默认命名空间。在 XSLT 1.0 中,处理这些问题的方法是使用命名空间前缀声明它,并在整个 XSLT 中使用该前缀。

试试这个 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>

请注意,此处前缀 (swe( 的选择是任意的。它可以是任何东西,只要命名空间 URI 匹配即可。

如果可以使用 XSLT,则在默认命名空间方面情况会稍微简单一些,因为您可以使用xpath-default-namespace代替,而不必担心添加前缀:

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

您正在循环访问objective元素,并尝试在每个元素中输出另一个objective元素的值,但没有。你应该在做

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

相反?

我的 XSL 将负责将输出转换为 <h2> 标记的文本。XSL 更加灵活,以防有人在简历中的某个位置嵌入您意想不到的目标。

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

我之所以使用 name(),是因为命名空间没有很好地定义,因此需要将其评估为字符串obj_body因此需要评估。

相关内容

  • 没有找到相关文章

最新更新