2012-01-09 6 views
1

XSLT 스타일 시트를 만드는 데 도움이 필요합니다. 즉, 노드를 선택하고 템플릿을 적용 할 수 없습니다.XSLT를 사용하여 노드를 선택할 수 없습니다.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
<xsl:output method="xml" encoding="utf-8" indent="yes"/> 

<xsl:template match="/"> 
    <searchresult> 
     <query> 
      <xsl:value-of select="/feed/title"/> 
     </query> 
     <xsl:apply-templates select="doc-template"/> 
    </searchresult> 
</xsl:template> 
<xsl:template name="doc-template" match="entry"> 
    <document> 
     <title> 
      <xsl:value-of select="title"/> 
     </title> 
     <snippet> 
      <xsl:value-of select="content"/> 
     </snippet> 
    </document> 
</xsl:template> 
</xsl:stylesheet> 

와 XML 파일입니다 : 다음은 입력 및 출력 XMLS 내 XSLT는

<?xml version="1.0" encoding="UTF-8"?> 
<feed xmlns:google="http://base.google.com/ns/1.0" xml:lang="en-US" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.w3.org/2005/Atom" xmlns:twitter="http://api.twitter.com/" xmlns:georss="http://www.georss.org/georss"> 
    <title>salsa - Twitter Search</title> 
    <entry> 
     <id>tag:search.twitter.com,2005:156464188011708416</id> 
     <published>2012-01-09T19:55:44Z</published> 
     <link type="text/html" href="http://twitter.com/RodFF/statuses/156464188011708416" rel="alternate"/> 
     <title>Al fin ponen mi tanda! @Anelito_Amed @samueltejeira @Elieser_Soriano @jose2734 #salsa #frankieruiz</title> 
     <content type="html">Al fin ponen mi tanda! @&lt;a class=" " href="http://twitter.com/Anelito_Amed"&gt;Anelito_Amed&lt;/a&gt; @&lt;a class=" " href="http://twitter.com/samueltejeira"&gt;samueltejeira&lt;/a&gt; @&lt;a class=" " href="http://twitter.com/Elieser_Soriano"&gt;Elieser_Soriano&lt;/a&gt; @&lt;a class=" " href="http://twitter.com/jose2734"&gt;jose2734&lt;/a&gt; #&lt;em&gt;salsa&lt;/em&gt; &lt;a href="http://search.twitter.com/search?q=%23frankieruiz" title="#frankieruiz" class=" "&gt;#frankieruiz&lt;/a&gt;</content> 
     <updated>2012-01-09T19:55:44Z</updated> 
     <link type="image/png" href="http://a1.twimg.com/profile_images/1672210480/IMG-20111008-00231_normal.jpg" rel="image"/> 
     <twitter:geo></twitter:geo> 
     <twitter:metadata> 
      <twitter:result_type>recent</twitter:result_type> 
     </twitter:metadata> 
     <twitter:source>&lt;a href="http://blackberry.com/twitter" rel="nofollow"&gt;Twitter for BlackBerry&#xae;&lt;/a&gt;</twitter:source> 
     <twitter:lang>es</twitter:lang> 
     <author> 
      <name>RodFF (Rodolfo Franceschi)</name> 
      <uri>http://twitter.com/RodFF</uri> 
     </author> 
    </entry> 
    <entry> 
     <id>tag:search.twitter.com,2005:156464182433288194</id> 
     <published>2012-01-09T19:55:42Z</published> 
     <link type="text/html" href="http://twitter.com/Olqa_N/statuses/156464182433288194" rel="alternate"/> 
     <title>No causo el efecto que imaginaste No me hizo el danio que tu pensaste no llore mas de lo que creiste no hiciste falta cuando te fuiste#salsa</title> 
     <content type="html">No causo el efecto que imaginaste No me hizo el danio que tu pensaste no llore mas de lo que creiste no hiciste falta cuando te fuiste#&lt;em&gt;salsa&lt;/em&gt;</content> 
     <updated>2012-01-09T19:55:42Z</updated> 
     <link type="image/png" href="http://a3.twimg.com/profile_images/1734507487/IMG01812-20110621-1025_jpg_normal.jpg" rel="image"/> 
     <twitter:geo></twitter:geo> 
     <twitter:metadata> 
      <twitter:result_type>recent</twitter:result_type> 
     </twitter:metadata> 
     <twitter:source>&lt;a href="http://ubersocial.com" rel="nofollow"&gt;&#xdc;berSocial for BlackBerry&lt;/a&gt;</twitter:source> 
     <twitter:lang>es</twitter:lang> 
     <author> 
      <name>Olqa_N (Olqa Lopez)</name> 
      <uri>http://twitter.com/Olqa_N</uri> 
     </author> 
    </entry> 
</feed> 
+1

가장 큰 문제는 원본 문서에 정의 된 네임 스페이스 중 하나를 사용하지 않는 것입니다. 최소한 xmlns = "http://www.w3.org/2005/Atom"'을 알아야합니다. XSLT 1.0을 사용해야합니까, 아니면 XSLT 2.0을 사용할 수 있습니까? –

답변

2

@Zachary 젊은 말했듯이, 당신은 XSLT 경로에 네임 스페이스 접두사를 사용해야 할 때 대상 요소 공백이 아닌 네임 스페이스 URI가 있어야합니다.

다음 문서에는 원본 문서에 사용 된 URI가 포함 된 xmlns:atom 선언이 포함되어 있습니다. 또한 XPath 단계에서 접두어 atom:을 사용합니다. 또한 "XSLT"유형의 관용구를 사용하여 수행하려고 시도했던 것을 달성하기 위해 다른 수정을했습니다.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 
    xmlns:atom="http://www.w3.org/2005/Atom"> 
<xsl:output method="xml" encoding="utf-8" indent="yes"/> 

<xsl:template match="/atom:feed"> 
<searchresult> 
<query> 
    <xsl:value-of select="atom:title"/> 
    </query> 
    <xsl:apply-templates select="atom:entry"/> 
</searchresult> 
</xsl:template> 

<xsl:template match="atom:entry"> 
<document> 
    <title> 
    <xsl:value-of select="atom:title"/> 
    </title> 
    <snippet> 
    <xsl:value-of select="atom:content"/> 
    </snippet> 
</document> 
</xsl:template> 
</xsl:stylesheet> 

그것은 (I 들여했습니다하는) 우리의 XML에 다음과 같은 출력을 생성합니다

<searchresult xmlns:atom="http://www.w3.org/2005/Atom"> 
    <query>salsa - Twitter Search</query> 
    <document> 
     <title>Al fin ponen mi tanda! @Anelito_Amed @samueltejeira @Elieser_Soriano @jose2734 #salsa #frankieruiz</title> 
     <snippet>Al fin ponen mi tanda! @&lt;a class=" " href="http://twitter.com/Anelito_Amed"&gt;Anelito_Amed&lt;/a&gt; @&lt;a class=" " href="http://twitter.com/samueltejeira"&gt;samueltejeira&lt;/a&gt; @&lt;a class=" " href="http://twitter.com/Elieser_Soriano"&gt;Elieser_Soriano&lt;/a&gt; @&lt;a class=" " href="http://twitter.com/jose2734"&gt;jose2734&lt;/a&gt; #&lt;em&gt;salsa&lt;/em&gt; &lt;a href="http://search.twitter.com/search?q=%23frankieruiz" title="#frankieruiz" class=" "&gt;#frankieruiz&lt;/a&gt;</snippet> 
    </document> 
    <document> 
     <title>No causo el efecto que imaginaste No me hizo el danio que tu pensaste no llore mas de lo que creiste no hiciste falta cuando te fuiste#salsa</title> 
     <snippet>No causo el efecto que imaginaste No me hizo el danio que tu pensaste no llore mas de lo que creiste no hiciste falta cuando te fuiste#&lt;em&gt;salsa&lt;/em&gt;</snippet> 
    </document> 
</searchresult> 
+0

감사합니다 !!! :) – user1139815

관련 문제