2014-02-05 2 views
0

저는 XSLT를 처음 사용하고 W3C 뉴스 피드에서 추출한 아톰 XML 파일을 HTML로 변환하려고합니다. XML 파일은 다음과 같습니다 : 지금은Xalan XSLT 처리 출력이 예기치 않은 경우

<?xml version="1.0" encoding="utf-8"?> 
<feed xmlns="http://www.w3.org/2005/Atom"> 
    <title>W3C News</title> 
    <link rel="alternate" type="text/html" href="http://www.w3.org/" /> 
    <link rel="self" type="application/atom+xml" href="http://www.w3.org/News/atom.xml" /> 
    <id>tag:www.w3.org,2008-09-29://4</id> 
    <updated>2013-09-06T16:31:45Z</updated> 

    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.34-en</generator> 


<entry> 
    <title>WebCrypto Key Discovery Working Draft Published</title> 
    <link rel="alternate" type="text/html" href="http://www.w3.org/News/2013.html#entry-9920" /> 
    <id>tag:www.w3.org,2013://4.9920</id> 

    <published>2013-08-22T16:40:18Z</published> 
    <updated>2013-08-22T16:40:18Z</updated> 

    <summary>The Web Cryptography Working Group has published a Working Draft of WebCrypto Key Discovery. This specification describes a JavaScript API for discovering named, origin-specific pre-provisioned cryptographic keys for use with the Web Cryptography API. Pre-provisioned keys are keys which have...</summary> 
    <author> 
     <name>W3C Staff</name> 
    </author> 

     <category term="Publication" scheme="http://www.sixapart.com/ns/types#category" /> 

     <category term="Web Design and Applications" scheme="http://www.sixapart.com/ns/types#category" /> 


    <content type="html" xml:lang="en" xml:base="http://www.w3.org/"> 

     <![CDATA[<p>The <a href="http://www.w3.org/2012/webcrypto/">Web Cryptography Working Group</a> has published a Working Draft of <a href="http://www.w3.org/TR/2013/WD-webcrypto-key-discovery-20130822/">WebCrypto Key Discovery</a>. This specification describes a JavaScript API for discovering named, origin-specific pre-provisioned cryptographic keys for use with the Web Cryptography API. Pre-provisioned keys are keys which have been made available to the user agent by means other than the generation, derivation, importation functions of the Web Cryptography API. Origin-specific keys are keys that are available only to a specified origin. Named keys are identified by a name assumed to be known to the origin in question and provisioned with the key itself. Learn more about the <a href="http://www.w3.org/Security/">Security Activity</a>.</p>]]> 
    </content> 
</entry> 

<entry> 
    <title>Three RDFa Recommendations Published</title> 
    <link rel="alternate" type="text/html" href="http://www.w3.org/News/2013.html#entry-9919" /> 
    <id>tag:www.w3.org,2013://4.9919</id> 

    <published>2013-08-22T16:15:02Z</published> 
    <updated>2013-08-22T16:15:02Z</updated> 

    <summary> The RDFa Working Group today published three RDFa Recommendations. RDFa lets authors put machine-readable data in HTML documents. Using RDFa, authors may turn their existing human-visible text and links into machine-readable data without repeating content. Today&apos;s publications were: HTML+RDFa...</summary> 
    <author> 
     <name>W3C Staff</name> 
    </author> 

     <category term="Publication" scheme="http://www.sixapart.com/ns/types#category" /> 

     <category term="Semantic Web" scheme="http://www.sixapart.com/ns/types#category" /> 


    <content type="html" xml:lang="en" xml:base="http://www.w3.org/"> 

     <![CDATA[<p> 
<a href="/2001/sw/" class="imageLink"> 
<img src="http://www.w3.org/Icons/SW/sw-cube.png" alt="Semantic Web Cube"/> 
</a> 
The <a href="/2010/02/rdfa/">RDFa Working Group</a> today published three RDFa Recommendations. RDFa lets authors put machine-readable data in HTML documents. Using RDFa, authors may turn their existing human-visible text and links into machine-readable data without repeating content. Today's publications were:</p> 

<ul class="show_items"> 
<li><a href="http://www.w3.org/TR/2013/REC-html-rdfa-20130822/">HTML+RDFa 1.1</a>, 
which defines rules and guidelines for adapting the RDFa Core 1.1 and RDFa Lite 1.1 specifications for use in HTML5 and XHTML5. The rules defined in this specification not only apply to HTML5 documents in non-XML and XML mode, but also to HTML4 and XHTML documents interpreted through the HTML5 parsing rules.</li> 
<li>The group also published two Second Editions for <a href="http://www.w3.org/TR/2013/REC-rdfa-core-20130822/">RDFa Core 1.1</a> and <a href="http://www.w3.org/TR/2013/REC-xhtml-rdfa-20130822/">XHTML+RDFa 1.1</a>, folding in the errata reported by the community since their publication as Recommendations in June 2012; all changes were editorial.</li> 
<li>The group also updated the a <a href="/TR/2013/NOTE-rdfa-primer-20130822/">RDFa 1.1 Primer</a>.</li> 
</ul> 
<p>Learn more about the <a href="/2001/sw/">Semantic Web Activity</a>.</p>]]> 
    </content> 
</entry> 

</feed> 

내가 원하는 건 목록으로 각 entry에서 title하는 것입니다. 내가 쓴 XSLT는 다음과 같습니다 :

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:p="http://www.w3.org/2005/Atom" 
    xmlns="http://www.w3.org/1999/xhtml" 
    version="1.0"> 

    <xsl:output method="xml" 
     omit-xml-declaration="yes" 
     doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" 
     doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/> 

    <xsl:template match="feed"> 
     <html> 
      <body> 
       <h1>W3C Atom Document</h1> 
       <ul> 
        <xsl:apply-templates/> 
       </ul> 
      </body> 
     </html> 
    </xsl:template> 

    <xsl:template match="entry"> 
     <li> 
      <xsl:value-of select="title" /> 
     </li> 
    </xsl:template> 
</xsl:stylesheet> 

의 Xalan을 실행 한 후, 생성 된 HTML 대신 모든 항목의 제목을 나열하는 모든 잎 노드에서 모든 값을 포함 할 것으로 보인다. 여기에 내 코드가 무엇이 잘못된지 잘 모르겠습니다. 고맙습니다.

답변

1

이것은 네임 스페이스 문제입니다. 로컬 이름이 feedentry이고 이름 공간이이 아닌 요소와 일치하는 템플릿을 정의했지만 원본 문서의 템플릿은 http://www.w3.org/2005/Atom 네임 스페이스에 있습니다. 따라서 템플릿이 아무 것도 아니므로 기본 템플릿 규칙이 대신 사용되므로 전체 소스 문서의 모든 텍스트 노드가 출력됩니다.

http://www.w3.org/2005/Atom 네임 스페이스에 바인딩 된 스타일 시트에서 접두어 p을 정의 했으므로 일치 패턴 및 선택 식에서 해당 접두사를 사용하기 만하면됩니다. 당신은뿐만 아니라 글로벌 title, id, generator 등의 텍스트를하지 않도록 나는 또한 apply-templates을 제한 한

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:p="http://www.w3.org/2005/Atom" 
    xmlns="http://www.w3.org/1999/xhtml" 
    version="1.0"> 

    <xsl:output method="xml" 
     omit-xml-declaration="yes" 
     doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" 
     doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/> 

    <xsl:template match="p:feed"> 
     <html> 
      <body> 
       <h1>W3C Atom Document</h1> 
       <ul> 
        <xsl:apply-templates select="p:entry"/> 
       </ul> 
      </body> 
     </html> 
    </xsl:template> 

    <xsl:template match="p:entry"> 
     <li> 
      <xsl:value-of select="p:title" /> 
     </li> 
    </xsl:template> 
</xsl:stylesheet> 

참고, 그냥 entry 요소를 선택합니다.

+0

아 맞아. 머리글에 네임 스페이스를 정의한 다음 XSLT 본문에서 자동으로 참조 할 것입니다. 규칙 오해. 그리고'select = "p : entry"알림을 주셔서 감사합니다. – goldfrapp04

관련 문제