2011-04-29 3 views
1

XML이 제대로 표시되지 않는 문제가 있습니다. 기본적으로 링크가 가득 찬 XML 문서가 있고 XSL 스타일 시트에서 XML을 정렬 된 목록으로 출력하기를 원합니다. 지금까지 모든 것이 올바르게 작동하고 스타일이 정확하지만 링크에 대한 데이터가 표시되지 않습니다. 양식 된 배경을 볼 수 있습니다. XML을 XSL에 올바르게 연결하고 Dreamweaver에서 XML 코드의 오류를 확인했습니다. 여기서 내가 무엇을 놓치고 있는지 확실하지 않니?XML이 XSL 스타일 시트로 표시되지 않음

test.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> 
    <open>&lt;li&gt;&lt;a href="/contest/test/goto.php?id=0" target="_blank"&gt;</open> 
    <description>Win a Macbook!</description> 
    <close>&lt;/a&gt;&lt;/li&gt;</close> 
</au> 
<au> 
    <open>&lt;li&gt;&lt;a href="/contest/test/goto.php?id=1" target="_blank"&gt;</open> 
    <description>Win a trip to Las Vegas!</description> 
    <close>&lt;/a&gt;&lt;/li&gt;</close> 
</au> 
</country> 

teststyle.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="country/au/open" /><xsl:value-of select="country/au/description"/><xsl:value-of select="country/au/close"/></span> 
     </ol> 
    </div> 
</xsl:for-each> 
</body> 
</html> 

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

답변

2

을 설치해야 "에 대한-각각"블록, 그 블록 내부의 모든 지침은있는 요소를 기준으로합니다 그들을 실행. 그 대신

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

방금 ​​

를 사용한다는 것을 의미
<xsl:value-of select="open" /> 

실제로 "열기"및 "닫기"블록의 < 및> 문자를 원한다고 가정하면 해당 링크에서 출력 이스케이프를 비활성화해야합니다. 그렇지 않으면 페이지에 이스케이프 코드가 생깁니다.

<?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로 HTML 코드를 탈출 퍼팅에 대해 권하고 싶습니다 : 여기

는 XSL의 전체, 작업 버전입니다. 무슨 일이 일어나고 있는지 명확하지 않으며, 모든 문자를 빠져 나가는 데 불필요한 혼란이 있습니다. 실제로 필요한 데이터를 파악하고 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> 

다음이 XSL이 동작을하게 약간의 (그리고 당신이 어떤 이스케이프 처리 할 필요가 없습니다!) 명확 :

<?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> 
+0

와우 , 감사! 방금 XML/XSL 학습을 시작 했으므로 아직 밧줄을 배우고 있습니다. – RayMicro

+0

+1 DOE 메커니즘을 저해하는 마지막 답변. –

관련 문제