Astronomy Picture of the Day 페이지 추가
이전 글에 이어서 계속….
바로 밑에 Ajax가 어쩌구 XMLHttpRequest가 저쩌구 했는데,
브라우저간 약간 씩 서로 다른 동작이나, IE인 경우엔 ActiveX 경고창이 뜨고해서,
서버에서 렌더링 해서 내리기로 변경….
코드도 의외로 간단.
$xml = new DomDocument;
$xml->load("http://www.jwz.org/cheesegrater/RSS/apod.rss");
$xsl = new DomDocument;
$xsl->load("apod.xsl");
$proc = new xsltprocessor;
$proc->importStyleSheet($xsl);
echo $proc->transformToXML($xml);
$xml->load("http://www.jwz.org/cheesegrater/RSS/apod.rss");
$xsl = new DomDocument;
$xsl->load("apod.xsl");
$proc = new xsltprocessor;
$proc->importStyleSheet($xsl);
echo $proc->transformToXML($xml);
apod.rss와 apod.xsl을 읽어와서
apos.rss를 apod.xsl을 이용해서 렌더링 해서 그냥 화면에 뿌려줌. 끝
apos.rss를 apod.xsl을 이용해서 렌더링 해서 그냥 화면에 뿌려줌. 끝
apod.xsl파일
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/rss/channel">
<xsl:value-of select="pubDate"/> by NASA
<xsl:value-of select="item/description"
disable-output-escaping = "yes" />
</xsl:template>
</xsl:stylesheet>
<xsl:output method="html"/>
<xsl:template match="/rss/channel">
<xsl:value-of select="pubDate"/> by NASA
<xsl:value-of select="item/description"
disable-output-escaping = "yes" />
</xsl:template>
</xsl:stylesheet>
/rss/item/description의 내용이 escape처리된 html 소스인데, 그냥 처리하면 화면에 html 소스가 출력된다.
value-of의 disable-output-escaping 속성 “yes”로 해주어야 한다.(이거 몰라서 한참을 찾았음)






