2012-10-24 2 views
1

저는 xsl을 사용하여 최소한 읽을 수있는 기본 xml 페이지를 얻으려고 약 6 ~ 7 시간을 소비했습니다. 그렇게 어려운가요? 아니면 그냥 큰 시간을 보내고 있습니다.xslt에서 xml을 간단하게 표시합니다.

내 XML 코드는

<?xml version="1.0" encoding="utf-8"?> 
<?xml-stylesheet type="text/xsl" href="recipepages.xsl"?><!DOCTYPE chefmaster [ 
<!ELEMENT chefmaster (recipe+)> 
    <!ELEMENT recipe (title, dishtype?, dishcategory?, chef, countryshown, episodeshown?, preparationtime, cookingtime, serves, caloriesperserve?, allergenslist?, ingredients, method, recommendedbeverage?, author*, mainingredientlink+)> 
    <!ATTLIST recipe cuisine (chinese|french|greek|indian|italian|japanese|mexican|notspecified|thai|western) #REQUIRED> 
    <!ELEMENT title (#PCDATA)> 
    <!ELEMENT dishtype (#PCDATA)> 
    <!ELEMENT dishcategory (#PCDATA)> 
    <!ELEMENT chef (#PCDATA)> 
    <!ELEMENT countryshown (#PCDATA)> 
    <!ELEMENT episodeshown (#PCDATA)> 
    <!ELEMENT preparationtime (#PCDATA)> 
    <!ELEMENT cookingtime (#PCDATA)> 
    <!ELEMENT serves (#PCDATA)> 
    <!ELEMENT caloriesperserve (#PCDATA)> 
    <!ELEMENT allergenslist (#PCDATA)> 
    <!ELEMENT ingredients (main, ingredient+)> 
    <!ELEMENT main (#PCDATA)> 
    <!ATTLIST main image CDATA #REQUIRED> 
    <!ELEMENT ingredient (#PCDATA)> 
    <!ATTLIST ingredient amount CDATA #IMPLIED> 
    <!ATTLIST ingredient units CDATA #IMPLIED> 
    <!ELEMENT method (step+)> 
    <!ELEMENT step (#PCDATA)> 
    <!ELEMENT recommendedbeverage (#PCDATA)> 
    <!ELEMENT author (givenname, surname)> 
    <!ELEMENT givenname (#PCDATA)> 
    <!ELEMENT surname (#PCDATA)> 
    <!ELEMENT mainingredientlink (#PCDATA)> 
]> 
<chefmaster> 
    <recipe cuisine="notspecified"> 
    <title>Quick carrot and coriander soup</title> 
    <dishtype>Entree</dishtype> 
    <dishcategory>Vegetarian</dishcategory> 
    <chef>Alison Good</chef> 
    <countryshown>Australia</countryshown> 
    <episodeshown>Season 2, Episode 1</episodeshown> 
    <preparationtime>5 mins</preparationtime> 
    <cookingtime>15 mins</cookingtime> 
    <serves>6</serves> 
    <caloriesperserve>85</caloriesperserve> 
    <allergenslist>None</allergenslist> 
    <ingredients> 
     <main image="http://1.bp.blogspot.com/-XaAgu2H_RDk/TmxXBKiOJ8I/AAAAAAAABQg/DrMxd41-b8s/s1600/carrot.jpg">Carrot</main> 
     <ingredient amount="4">Large carrots, peeled and cut into large chunks</ingredient> 
     <ingredient amount="1" units="tablespoon">Olive oil</ingredient> 
     <ingredient amount="1/4">Large onion, diced</ingredient> 
     <ingredient amount="4" units="cups">Vegetable stock</ingredient> 
     <ingredient>Large bunch of fresh coriander, de-stemmed and roughly chopped</ingredient> 
    </ingredients> 
    <method> 
     <step>1. Heat the oil in a large saucepan over medium heat and saute the carrots and onion for a few minutes until the onion has softened a little.</step> 
     <step>2. Pour in the vegetable stock and add the coriander. Bring to a boil and cook until the carrots are tender; about 10 minutes. Remove from the heat and allow to cool slightly.</step> 
     <step>3. Puree the soup until smooth using a hand-blender or food processor. Reheat before serving if necessary.</step> 
    </method> 
    <recommendedbeverage>Water</recommendedbeverage> 
    <author> 
     <givenname>Sarah</givenname> 
     <surname>May</surname> 
    </author> 
    <mainingredientlink>http://en.wikipedia.org/wiki/Carrot</mainingredientlink> 
    </recipe> 
    <recipe cuisine="greek"> 
    <title>Prawns (garides) saganaki</title> 
    <dishtype>Entree</dishtype> 
    <chef>Alison Good</chef> 
    <countryshown>Australia</countryshown> 
    <episodeshown>Season 2, Episode 3</episodeshown> 
    <preparationtime>5 mins</preparationtime> 
    <cookingtime>35 mins</cookingtime> 
    <serves>4</serves> 
    <caloriesperserve>287</caloriesperserve> 
    <allergenslist>Seafood</allergenslist> 
    <ingredients> 
     <main image="http://images.wikia.com/prawnhub/images/d/df/Going_to_be_a_Fairy_Prawn.jpg">Prawns</main> 
     <ingredient amount="500" units="grams">Raw king prawns</ingredient> 
     <ingredient amount="3" units="tablespoons">Olive oil</ingredient> 
     <ingredient amount="1">Onion, chopped</ingredient> 
     <ingredient amount="1" units="teaspoon">Freshly chopped parsley</ingredient> 
     <ingredient>Large bunch of fresh coriander, de-stemmed and roughly chopped</ingredient> 
     <ingredient amount="1" units="cup">White wine</ingredient> 
     <ingredient amount="400" units="gram">Tin chopped tomatoes, drained</ingredient> 
     <ingredient amount="1" units="clove">Garlic, finely chopped</ingredient> 
     <ingredient amount="200" units="grams">Feta cheese, cubed</ingredient> 
    </ingredients> 
    <method> 
     <step>1. Place the prawns in a pot and add enough water to cover them. Boil for 5 minutes, then drain, reserving the liquid and set aside.</step> 
     <step>2. Heat about 2 tablespoons of oil in a saucepan. Add the onion and cook and stir until the onions are soft. Mix in the parsley, wine, tomatoes, garlic and remaining olive oil.</step> 
     <step>3. Simmer, stirring occasionally, for about 30 minutes, or until the sauce is thickened.</step> 
     <step>4. While the sauce is simmering, the prawns should have become cool enough to handle. First remove the legs by pinching them, and then pull off the shells, leaving the head and tail on.</step> 
     <step>5. When the sauce has thickened, stir in the prawns. Bring to a simmer, and cook for about 5 minutes.</step> 
     <step>6. Add the feta cheese and remove from the heat. Let stand until the cheese starts to melt. Serve warm.</step> 
    </method> 
    <author> 
     <givenname>George</givenname> 
     <surname>Adams</surname> 
    </author> 
    <author> 
     <givenname>Alex</givenname> 
     <surname>Antonovich</surname> 
    </author> 
    <mainingredientlink>http://en.wikipedia.org/wiki/Shrimp_meat</mainingredientlink> 
    </recipe> 
    <recipe cuisine="greek"> 
    <title>Spicy Baked Feta</title> 
    <dishtype>Entree</dishtype> 
    <dishcategory>Vegetarian</dishcategory> 
    <chef>Neil Perry</chef> 
    <countryshown>Australia</countryshown> 
    <episodeshown>Season 2, Episode 3</episodeshown> 
    <preparationtime>3 mins</preparationtime> 
    <cookingtime>10 mins</cookingtime> 
    <serves>4</serves> 
    <caloriesperserve>267</caloriesperserve> 
    <allergenslist>Chilli</allergenslist> 
    <ingredients> 
     <main image="http://www.gaganisbros.com.au/images/Greek_Feta_Texture.jpg">Feta Cheese</main> 
     <ingredient amount="250" units="gram">Slab of feta cheese</ingredient> 
     <ingredient amount="3 to 4" units="tablespoons">Chilli flakes</ingredient> 
     <ingredient units="pinch">Oregano</ingredient> 
     <ingredient>Olive oil</ingredient> 
    </ingredients> 
    <method> 
     <step>1. Preheat oven 150 degrees C.</step> 
     <step>2. Place feta in small baking dish. Drizzle with olive oil. Cover liberally with chili flakes, and a sprinkle of oregano.</step> 
     <step>3. Bake uncovered for 10 minutes until feta is soft.</step> 
     <step>4. Serve with crusty bread or toast.</step> 
    </method> 
    <recommendedbeverage>Glass of shiraz</recommendedbeverage> 
    <author> 
     <givenname>Christina</givenname> 
     <surname>Motso</surname> 
    </author> 
    <mainingredientlink>http://en.wikipedia.org/wiki/Feta</mainingredientlink> 
    <mainingredientlink>http://culinaryarts.about.com/od/glossary/g/Feta.htm</mainingredientlink> 
    </recipe> 
</chefmaster> 

는 요리법에 XSL 문서에서 몇 가지 기본적인 라인에서 쉽게 읽을 수 있도록 순서를 표시 할 수 있습니다 기본입니까?

+1

실제로 표시하는 방법을 포함시켜야합니다. 선언 프로그래밍이나 (일종의) 함수 프로그래밍에 익숙하지 않아도 처음에는 약간 외래로 보일지라도 꽤 쉽습니다. –

+0

정확하게 원하는 출력과 변환을 구현 (적용) 할 규칙을 제공하십시오. –

답변

0

몇 가지 일반 규칙을 사용하여 HTML로 빠르게 변환 한 다음, 더 규칙을 추가하여 더 규칙을 맞춤 설정할 수 있습니다. 여기에는 문서의 깊이에 따라 요소와 속성을 표시하는 시작 도구가 있습니다. 아름다운 것은 아니지만 출발점입니다.

<?xml version='1.0'?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > 

<xsl:template match="/"> 
    <html><body><xsl:apply-templates/></body></html> 
</xsl:template> 

<xsl:template match="*/*"> 
    <h1> 
    <xsl:value-of select="name()"/> 
    <xsl:apply-templates select="@*"/> 
    </h1> 
    <table> 
    <xsl:apply-templates select="*"/> 
    </table> 
</xsl:template> 

<xsl:template match="*/*/*"> 
    <tr> 
    <td><xsl:value-of select="name()"/></td> 
    <td><xsl:apply-templates/></td> 
    </tr> 
</xsl:template> 

<xsl:template match="*/*/*/*"> 
    <dt> 
    <xsl:value-of select="name()"/> 
    <xsl:apply-templates select="@*"/> 
    </dt> 
    <dd><xsl:value-of select="."/></dd> 
</xsl:template> 

<xsl:template match="@*"> 
    <xsl:value-of select="concat(' ', name(), ': ', .)"/> 
</xsl:template> 
</xsl:stylesheet> 
관련 문제