这可能属于了解基础知识的类别,但我找不到答案,所以我将不胜感激地推动正确的方向。
删除 DTD 后,我可以在浏览器 (Chrome) 中看到打印输出。有效的 XML
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<recipes>
<recipe is="test">
<ind1>Test1</ind1>
<ind2>Test2</ind2>
</recipe>
</recipes>
XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="recipes/recipe">
<h2><xsl:value-of select="ind1"/></h2>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
很好,但是使用此XML,它将无法仅产生空白屏幕:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE recipes SYSTEM "recipes.dtd">
<recipes>
<recipe is="test">
<ind1>Test1</ind1>
<ind2>Test2</ind2>
</recipe>
</recipes>
DTD:
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT recipes (recipe*)>
<!ELEMENT recipe (ind1,ind2)>
<!ELEMENT ind1 (#PCDATA|recipe*)>
<!ELEMENT ind2 (#PCDATA|recipe*)>
如果我理解了到目前为止我学到的所有东西,DTD是要走的路,但缺少一些基本的东西,如果你能把大象指在客厅里并帮助我前进,我将不胜感激。
谢谢你的时间!
您的 XML 对于您的 DTD 无效
(缺少属性is
),并且 DTD 在混合内容元素 ind1 和 ind2 的声明中包含错误。使用以下 DTD,我能够应用您的转换:
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT recipes (recipe*)>
<!ELEMENT recipe (ind1,ind2)>
<!ATTLIST recipe is CDATA #IMPLIED>
<!ELEMENT ind1 (#PCDATA|recipe)*>
<!ELEMENT ind2 (#PCDATA|recipe)*>