我是XML-XSLT转换的新手。我有以下XML文件和相应的XSLT文件,但由于某种原因,它没有显示任何传递h2,这是一个HTML。任何帮助都会很棒!
我检查了命名空间以确保它与XML文档匹配,我也尝试在W3站点上运行代码。
两个文件都在下面:
XML
Test
XSLT
<?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>
答案 0 :(得分:1)
您提到您已“检查了命名空间以确保它与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>
答案 1 :(得分:0)
您正在遍历objective
元素,并尝试在每个元素中输出另一个objective
元素的值,但没有任何元素。你应该做什么
<xsl:value-of select="obj_body"/>
代替?
答案 2 :(得分:0)
我的XSL将负责将输出转换为<h2>
标记的文本。如果有人在简历中的某个地方嵌入了你没想到的目标,那么XSL会更灵活。
<xsl:for-each select="//*[name()='obj_body']">
<h2><xsl:value-of select="."/></h2>
</xsl:for-each>
我使用name()
因为命名空间没有很好地定义,所以obj_body
需要被评估为字符串。