messier 페이지에 type icon 표시 추가

January 10th, 2007 4 Comments »

메시에 페이지에 가면 메시에 DB가 있다.
테이블 보기에서는 모든 정보가 보이지만,
촬영 시기별 보기나, 촬영 장비별 보기에서는 대상이 은하인지, 성운인지 알 방법이 없어서,
모든 대상 옆에 icon을 붙였다.
각 대상은 다음과 같다.

  • 행성상 성운/초신성 잔해물 :
  • 성운 :
  • 은하 :
  • 산개 성단 :
  • 구상 성단 :
  • 이중성, 성군(星群), 기타 :

(icon 이미지는 천문노트에 있는 별 있는거 안에 있는 이미지를 편집해서 사용했다.
이 글을 쓰고나서 제작자의 양해를 구해야지…)

messier페이지는 서버에서 html로 렌더링 해서 뿌리기 때문에, 소스보기해도 알 방법은 없지만,
현재는 messier DB를 xml 로 저장해서

<object>
	<num>M1</num>
	<ngc>NGC1952</ngc>
	<const>Taurus</const>
	<constabbr>Tau</constabbr>
	<type>Supernova Remnant</type>
	<subtype>-</subtype>
	<ra>05 34.5</ra>
	<dec>+22 01</dec>
	<mag>8.4</mag>
	<diameter>6</diameter>
	<distance>6.3</distance>
	<desc>Crab Nebula</desc>	
</object>

xslt를 여러개 만들어서 각 보기마다 실시간으로 렌더링해서 html을 생성하는 구조이다.
이를 위해서 <xsl:choose><xsl:when>을 사용했다.

아래 소스는 xslt 안에 있는 type에 대한 <xsl:template>이다.

<xsl:template match="type">
	<xsl:choose>
		<xsl:when test="contains(.,'Open Cluster')">
			<img src="/images/deepskyicon/OpenCluster.png"/>
		</xsl:when>
		<xsl:when test="contains(.,'Galaxy')">
			<img src="/images/deepskyicon/Galaxy.png"/>
		</xsl:when>
		<xsl:when test="contains(.,'Globular Cluster')">
			<img src="/images/deepskyicon/GlobularCluster.png"/>
		</xsl:when>
		<xsl:when test="contains(.,'Nebula')">
			<img src="/images/deepskyicon/DiffuseNebular.png" />
		</xsl:when>
		</xsl:when>
		<xsl:otherwise>
			<img src="/images/deepskyicon/BinaryStar.png" />
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

몇가지 패턴을 알수 있다.

  • 거리순 보기를 보면, 은하들은 죄다 거리가 멀다는 걸 알수 있다. - 당근 나머지 대상은 우리 은하 내의 대상이니까
  • 시기별 보기를 보면, 2~3월엔 거진 외부 은하들만 바글바글하고 5~6월(여름), 11~12월(겨울)엔 은하 찾기가 힘들다. - 여름 겨울철엔 은하수(즉 우리은하)가 흐르니까 우리은하내에 있는 성운, 성단들이 주로 보이는 게다.
  • 밝기별 보기를 보면, 은하들은 순위가 떨어진다. (독보적인 M31을 제외하면) - 역시 은하들은 거리가 머니까…

Astronomy Picture of the Day 페이지 추가

June 22nd, 2006 7 Comments »

이전 글에 이어서 계속….
바로 밑에 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);

apod.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>

/rss/item/description의 내용이 escape처리된 html 소스인데, 그냥 처리하면 화면에 html 소스가 출력된다.
value-of의 disable-output-escaping 속성 “yes”로 해주어야 한다.(이거 몰라서 한참을 찾았음)