XML未与XSL样式表一起显示

XML未与XSL样式表一起显示,xml,xslt,Xml,Xslt,我的XML显示不正确,有一个问题。基本上,我有一个充满链接的XML文档,我希望XSL样式表以有序列表的形式输出XML。到目前为止,一切正常,样式正确,但没有显示链接的数据。你只看到样式化的背景。我将XML正确地连接到XSL,Dreamweaver毫不费力地验证了XML代码。不知道我在这里遗漏了什么 test.xml lia href=“/contest/test/goto.php?id=0”target=“\u blank” 赢一本Macbook! /a/李 lia href=“/contes

我的XML显示不正确,有一个问题。基本上,我有一个充满链接的XML文档,我希望XSL样式表以有序列表的形式输出XML。到目前为止,一切正常,样式正确,但没有显示链接的数据。你只看到样式化的背景。我将XML正确地连接到XSL,Dreamweaver毫不费力地验证了XML代码。不知道我在这里遗漏了什么

test.xml

lia href=“/contest/test/goto.php?id=0”target=“\u blank”
赢一本Macbook!
/a/李
lia href=“/contest/test/goto.php?id=1”target=“\u blank”
赢得拉斯维加斯之旅!
/a/李
teststyle.xsl

]>
无标题文件
当您有一个“for each”块时,该块中的所有指令都是相对于您运行它们的元素的。这意味着

<xsl:value-of select="country/au/open" />

你应该用

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

此外,假设您确实需要“打开”和“关闭”块中的<和>字符,则需要禁用这些链接上的输出转义。否则,您的页面中会出现转义码

以下是XSL的完整工作版本:

<?xml version="1.0" encoding="utf-8"?><!-- DWXMLSource="test.xml" -->
<!DOCTYPE xsl:stylesheet  [
<!ENTITY nbsp   "&#160;">
<!ENTITY copy   "&#169;">
<!ENTITY reg    "&#174;">
<!ENTITY trade  "&#8482;">
<!ENTITY mdash  "&#8212;">
<!ENTITY ldquo  "&#8220;">
<!ENTITY rdquo  "&#8221;"> 
<!ENTITY pound  "&#163;">
<!ENTITY yen    "&#165;">
<!ENTITY euro   "&#8364;">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0     Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:template match="/">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Untitled Document</title>
</head>

<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
    <xsl:for-each select="country/au">
        <div style="background-color:teal;color:white;padding:4px">
            <ol>
                <span style="font-weight:bold"><xsl:value-of select="open" disable-output-escaping="yes" /><xsl:value-of select="description"/><xsl:value-of select="close" disable-output-escaping="yes"/></span>
            </ol>
        </div>
    </xsl:for-each>
</body>
</html>

</xsl:template>
</xsl:stylesheet>

]>
无标题文件
但是,我强烈建议不要像那样将转义的html代码放入xml中。现在还不太清楚发生了什么,在逃离所有角色的过程中有很多不必要的混乱。最好弄清楚您实际需要哪些数据,并使用XSL将数据转换为有效的HTML。例如,如果将XML数据文件更改为:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="teststyle.xsl"?>
<country xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<au>
    <url>/contest/test/goto.php?id=0</url>
    <target>_blank</target>
    <description>Win a Macbook!</description>
</au>
<au>
    <url>/contest/test/goto.php?id=1</url>
    <target>_blank</target>
    <description>Win a trip to Las Vegas!</description>
</au>
</country>

哇,谢谢!我今天刚开始学习XML/XSL,所以我还在学习诀窍。
<?xml version="1.0" encoding="utf-8"?><!-- DWXMLSource="test.xml" -->
<!DOCTYPE xsl:stylesheet  [
<!ENTITY nbsp   "&#160;">
<!ENTITY copy   "&#169;">
<!ENTITY reg    "&#174;">
<!ENTITY trade  "&#8482;">
<!ENTITY mdash  "&#8212;">
<!ENTITY ldquo  "&#8220;">
<!ENTITY rdquo  "&#8221;"> 
<!ENTITY pound  "&#163;">
<!ENTITY yen    "&#165;">
<!ENTITY euro   "&#8364;">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0     Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:template match="/">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Untitled Document</title>
</head>

<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
    <xsl:for-each select="country/au">
        <div style="background-color:teal;color:white;padding:4px">
            <ol>
                <span style="font-weight:bold"><xsl:value-of select="open" disable-output-escaping="yes" /><xsl:value-of select="description"/><xsl:value-of select="close" disable-output-escaping="yes"/></span>
            </ol>
        </div>
    </xsl:for-each>
</body>
</html>

</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="teststyle.xsl"?>
<country xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<au>
    <url>/contest/test/goto.php?id=0</url>
    <target>_blank</target>
    <description>Win a Macbook!</description>
</au>
<au>
    <url>/contest/test/goto.php?id=1</url>
    <target>_blank</target>
    <description>Win a trip to Las Vegas!</description>
</au>
</country>
<?xml version="1.0" encoding="utf-8"?><!-- DWXMLSource="test.xml" -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0     Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:template match="/">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>

<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
    <xsl:for-each select="country/au">
        <div style="background-color:teal;color:white;padding:4px">
            <ol style="font-weight:bold">
                <a href="{url}" target="{target}"><xsl:value-of select="description"/></a>
            </ol>
        </div>
    </xsl:for-each>
</body>
</html>

</xsl:template>
</xsl:stylesheet>