我有一个我正在进行的课程项目,但是我已经遇到了困难而且不知道该怎么做的地方。我的XSL(style6.xsl)工作到一定程度,但它创建文本而不是包装我的xml(Project6style.xml)块,所以我有2组文本,但一个不包含在任何标签中。我花了一整天的时间试图弄清楚它为什么会这样做,但我无法弄明白。我希望有人能够看一眼。
如果有人可以提供帮助,我们将不胜感激!
https://www.mediafire.com/?4b74nb1iltdqsqx
文件参考:
style6.xsl(我需要编辑的内容,因此它看起来很特定)
Project6style.xml(在课程项目文件夹中给我的内容)
Tutorial.06 Project.doc(作业单词文档)
XSL Current Output.html(我当前的xsl文件给了我)
XSL输出 - 它应该是什么(我假设我的教授希望它看起来像什么)
不想下载的代码:
XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0"/>
<xsl:template match="project">
<html>
<body>
<xsl:apply-templates/>
<h1>
<xsl:value-of select="student"/>
</h1>
<h2>
<xsl:value-of select="date"/>
</h2>
</body>
</html>
</xsl:template>
<xsl:template match="objective">
<xsl:apply-templates/>
<h4>
<xsl:value-of select=".//name"/>
</h4>
<div>
<xsl:value-of select="description"/>
</div>
</xsl:template>
</xsl:stylesheet>
XML:
<?xml version="1.0"?>
<!-- XML Project 6 -->
<?xml-stylesheet type="text/xsl" href="style6.xsl" ?>
<project>
<student>Student</student>
<date>Date</date>
<objective>
<name>Working with XSL</name>
<description>XSL is composed of three parts: XSL-FO
(Extensible Style sheet Language - Formatting Objects),
XSLT (Extensible Style sheet Language Transformations),
and XPath. XSL-FO is used to implement page layout and design.
XSLT is used to transform XML content into another presentation format.
XPath is used to locate information from an XML document
and perform operations and calculations upon that content.
</description>
</objective>
<objective>
<name>Introducing XSLT style sheets and processors</name>
<description>An XSLT style sheet contains instructions for transforming
the contents of an XML document into another format. An XSLT style
sheet document is itself an XML document, but has an extension .xsl.
An XSLT style sheet converts a source document of XML content into
a result document containing the markup codes and other instructions
for formatting.
</description>
</objective>
<objective>
<name>Creating an XSLT style sheet</name>
<description>To attach an XML file to the style sheet,
insert the processing instruction following the first line
in the document. An XSLT style sheet has the general structure
of all XML documents.
</description>
</objective>
</project>
HTML结果(我的HTML文件以这两个文件的当前状态显示的内容):
Student
Date
Working with XSL
XSL is composed of three parts: XSL-FO
(Extensible Style sheet Language - Formatting Objects),
XSLT (Extensible Style sheet Language Transformations),
and XPath. XSL-FO is used to implement page layout and design.
XSLT is used to transform XML content into another presentation format.
XPath is used to locate information from an XML document
and perform operations and calculations upon that content.
<h4>Working with XSL</h4><div>XSL is composed of three parts: XSL-FO
(Extensible Style sheet Language - Formatting Objects),
XSLT (Extensible Style sheet Language Transformations),
and XPath. XSL-FO is used to implement page layout and design.
XSLT is used to transform XML content into another presentation format.
XPath is used to locate information from an XML document
and perform operations and calculations upon that content.
</div>
Introducing XSLT style sheets and processors
An XSLT style sheet contains instructions for transforming
the contents of an XML document into another format. An XSLT style
sheet document is itself an XML document, but has an extension .xsl.
An XSLT style sheet converts a source document of XML content into
a result document containing the markup codes and other instructions
for formatting.
<h4>Introducing XSLT style sheets and processors</h4><div>An XSLT style sheet contains instructions for transforming
the contents of an XML document into another format. An XSLT style
sheet document is itself an XML document, but has an extension .xsl.
An XSLT style sheet converts a source document of XML content into
a result document containing the markup codes and other instructions
for formatting.
</div>
Creating an XSLT style sheet
To attach an XML file to the style sheet,
insert the processing instruction following the first line
in the document. An XSLT style sheet has the general structure
of all XML documents.
<h4>Creating an XSLT style sheet</h4><div>To attach an XML file to the style sheet,
insert the processing instruction following the first line
in the document. An XSLT style sheet has the general structure
of all XML documents.
</div>
<h1>Student</h1><h2>Date</h2>
答案 0 :(得分:0)
这是一种可能的样式表,只是坚持输入XML文档的结构:
<?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" version="4.0" />
<xsl:template match="objective">
<h4><xsl:value-of select="name" /></h4>
<div><xsl:value-of select="description" /></div>
</xsl:template>
<xsl:template match="project">
<h1><xsl:value-of select="student" /></h1>
<h2><xsl:value-of select="date" /></h2>
<xsl:apply-templates select="objective" />
</xsl:template>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="project" />
</body>
</html>
</xsl:template>
</xsl:stylesheet>
注意:我想具体说明我的apply-templates
元素的目标(因此select="..."
属性),而有些人更喜欢隐式选择;选择完全取决于你。