2012-10-16 3 views
0

저는 XSLT를 배우고 몇 가지 문제를 겪고 있습니다. 이 줄 <xsl:template match="response/results">은 xlst 프로세스를 <results> 요소 내의 해당 요소로만 제한한다고 생각합니까 ???이것이 출력되는 이유는 무엇입니까?

일부 초기 값이 출력되며 이유를 알 수 없습니다.

manhattan WMOS 
true 
false 
60 
1 
10 
0 

XML :

<?xml version="1.0" encoding="UTF-8" ?> 
<response version="2"> 
    <query>manhattan WMOS</query> 
    <location></location> 
    <dupefilter>true</dupefilter> 
    <highlight>false</highlight> 
    <totalresults>60</totalresults> 
    <start>1</start> 
    <end>10</end> 
    <pageNumber>0</pageNumber> 
    <results> 
     <result> 
      <jobtitle>Manhattan Associates WMoS QA Analyst</jobtitle> 
      <company>CMAC Inc</company> 
      <city>Asheville</city> 
      <state>NC</state> 
      <country>US</country> 
      <formattedLocation>Asheville, NC</formattedLocation> 
      <source>JobServe USA</source> 
      <date>Thu, 11 Oct 2012 15:20:31 GMT</date> 
      <snippet>Manhattan Associtates WMoS Loads of Documentation and detail required for this position Immediate opening for 2 Senior QA Analysts Project: Manhattan (WMOS... </snippet> 
      <url>http://www.indeed.com/viewjob?jk=06bef17e206740d3&amp;qd=Cg_V6UykGXt-ccaEWxs0BA1LyorWd-7Tcbya1NtZKa9WZ1DtngXSHw91EGjVCy_rntA_Y_5cpbSuoLd44_xEjXNG-vBD0DC792zHqZRp6lE&amp;indpubnum=1813651566614396&amp;atk=179li835k18b17ae</url> 
      <onmousedown>indeed_clk(this, &#039;5585&#039;);</onmousedown> 
      <jobkey>06bef17e206740d3</jobkey> 
      <sponsored>false</sponsored> 
      <expired>false</expired> 
      <formattedLocationFull>Asheville, NC</formattedLocationFull> 
      <formattedRelativeTime>5 days ago</formattedRelativeTime> 
     </result> 
     <result> 
      <jobtitle>Software Analyst - WMOS</jobtitle> 
      <company>Manhattan Associates</company> 
      <city>Atlanta</city> 
      <state>GA</state> 
      <country>US</country> 
      <formattedLocation>Atlanta, GA</formattedLocation> 
      <source>Manhattan Associates</source> 
      <date>Mon, 01 Oct 2012 21:02:50 GMT</date> 
      <snippet>innovations include: Manhattan SCOPE® a portfolio of... Position open in Atlanta Office. About Manhattan Associates: Manhattan Associates is at the forefront of... </snippet> 
      <url>http://www.indeed.com/viewjob?jk=a17a7c578a779db8&amp;qd=Cg_V6UykGXt-ccaEWxs0BA1LyorWd-7Tcbya1NtZKa9WZ1DtngXSHw91EGjVCy_rntA_Y_5cpbSuoLd44_xEjXNG-vBD0DC792zHqZRp6lE&amp;indpubnum=1813651566614396&amp;atk=179li835k18b17ae</url> 
      <onmousedown>indeed_clk(this, &#039;5585&#039;);</onmousedown> 
      <jobkey>a17a7c578a779db8</jobkey> 
      <sponsored>false</sponsored> 
      <expired>false</expired> 
      <formattedLocationFull>Atlanta, GA</formattedLocationFull> 
      <formattedRelativeTime>14 days ago</formattedRelativeTime> 
     </result> 

XSLT :

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="html" indent="yes"/> 
<xsl:param name="ItemsToShow" select="'2'"/> 
<xsl:param name="ShowItemDetails" select="'true'"/> 
<xsl:param name="ShowItemDate" select="'true'"/> 
<xsl:param name="Locale"/> 
<xsl:param name="Target"/> 
    <xsl:variable name="apos">'</xsl:variable> 

<xsl:template name="google_analytics_event_tracking"> 
    <xsl:param name="link_category" /> 
    <xsl:param name="link_sub_category" /> 
    <xsl:param name="link_data" /> 

    <xsl:value-of select="concat('_gaq.push([', $apos, '_trackEvent', $apos, ',', $apos, $link_category, $apos, ',', $apos, $link_sub_category, $apos, ',', $apos, $link_data, $apos,')]')" /> 
</xsl:template> 
    <xsl:template match="response/results"> 
    <xsl:for-each select="result[position()&lt;=$ItemsToShow or $ItemsToShow&lt;1]"> 
     <xsl:variable name="jobOutboundLinkAction"> 
      <xsl:call-template name="google_analytics_event_tracking"> 
       <xsl:with-param name="link_category" select="'indeed.com'" /> 
       <xsl:with-param name="link_sub_category" select="'none'" /> 
       <xsl:with-param name="link_data" select="url" /> 
      </xsl:call-template> 
     </xsl:variable> 
     <div class="jobWrapper"> 
      <div class="jobTitle"> 
       <a href="{url}"> 
        <xsl:attribute name="target"> 
         <xsl:value-of select="$Target"/> 
        </xsl:attribute> 
        <xsl:attribute name="onclick"> 
         <xsl:value-of select="$jobOutboundLinkAction"/> 
        </xsl:attribute> 
        <xsl:value-of select="jobtitle"/> 
       </a> 
      </div> 
      <xsl:if test="$ShowItemDate='true'"> 
       <h6> 
        <xsl:value-of select="date"/> 
       </h6> 
      </xsl:if> 
      <xsl:if test="$ShowItemDetails='true'"> 
       Company: <xsl:value-of select="company" disable-output-escaping="yes"/> 
       <br /> 
       <xsl:value-of select="formattedLocation" disable-output-escaping="yes"/> 
       <br /> 
       <p> 
        <xsl:value-of select="snippet" disable-output-escaping="yes"/> 
       </p> 
      </xsl:if> 
      <div class="cleaner"></div> 
     </div> 
    </xsl:for-each> 
</xsl:template> 
</xsl:stylesheet> 

출력 :

manhattan WMOS 
true 
false 
60 
1 
10 
0 
<div class="jobWrapper"> 
    <div class="jobTitle"> 
     <a href="http://www.indeed.com/viewjob?jk=06bef17e206740d3&amp;qd=Cg_V6UykGXt-ccaEWxs0BA1LyorWd-7Tcbya1NtZKa9WZ1DtngXSHw91EGjVCy_rntA_Y_5cpbSuoLd44_xEjXNG-vBD0DC792zHqZRp6lE&amp;indpubnum=1813651566614396&amp;atk=179li835k18b17ae" target="" onclick="_gaq.push(['_trackEvent','indeed.com','none','http://www.indeed.com/viewjob?jk=06bef17e206740d3&amp;qd=Cg_V6UykGXt-ccaEWxs0BA1LyorWd-7Tcbya1NtZKa9WZ1DtngXSHw91EGjVCy_rntA_Y_5cpbSuoLd44_xEjXNG-vBD0DC792zHqZRp6lE&amp;indpubnum=1813651566614396&amp;atk=179li835k18b17ae')]">Manhattan Associates WMoS QA Analyst</a> 
    </div> 
    <h6>Thu, 11 Oct 2012 15:20:31 GMT</h6> 
    Company: CMAC Inc<br> 
     Asheville, NC<br> 
      <p>Manhattan Associtates WMoS Loads of Documentation and detail required for this position Immediate opening for 2 Senior QA Analysts Project: Manhattan (WMOS... </p> 
      <div class="cleaner"></div> 
     </div> 
     <div class="jobWrapper"> 
      <div class="jobTitle"> 
       <a href="http://www.indeed.com/viewjob?jk=a17a7c578a779db8&amp;qd=Cg_V6UykGXt-ccaEWxs0BA1LyorWd-7Tcbya1NtZKa9WZ1DtngXSHw91EGjVCy_rntA_Y_5cpbSuoLd44_xEjXNG-vBD0DC792zHqZRp6lE&amp;indpubnum=1813651566614396&amp;atk=179li835k18b17ae" target="" onclick="_gaq.push(['_trackEvent','indeed.com','none','http://www.indeed.com/viewjob?jk=a17a7c578a779db8&amp;qd=Cg_V6UykGXt-ccaEWxs0BA1LyorWd-7Tcbya1NtZKa9WZ1DtngXSHw91EGjVCy_rntA_Y_5cpbSuoLd44_xEjXNG-vBD0DC792zHqZRp6lE&amp;indpubnum=1813651566614396&amp;atk=179li835k18b17ae')]">Software Analyst - WMOS</a> 
      </div> 
      <h6>Mon, 01 Oct 2012 21:02:50 GMT</h6> 
      Company: Manhattan Associates<br> 
       Atlanta, GA<br> 
        <p>innovations include: Manhattan SCOPE® a portfolio of... Position open in Atlanta Office. About Manhattan Associates: Manhattan Associates is at the forefront of... </p> 
        <div class="cleaner"></div> 
       </div> 
+0

포럼 사이트와 달리 "감사"또는 "모든 도움을 주셨습니다"또는 [그래서]의 서명을 사용하지 않습니다. "[안녕하세요, '고마워,'태그 라인 및 인사말을 게시물에서 삭제해야합니까?] (http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be 참조) (제목에서 "태그"를 포함해야합니까?) (http://meta.stackexchange.com/questions/19190/) ", 제목을 수정했습니다. 여기서 합의는 "안돼,하지 말았 어야지." –

+0

@JohnSaunders 그것을 얻었다. –

+0

여기에서 실행할 수있다 : http://www.xsltcake.com/slices/YWkbQL –

답변

0
아래의 결과에서, 당신은 결과의 시작 부분에 다음과 같이 표시됩니다

아, 찾았습니다. this link

추가 된이 원하지 않는 필터링하기 :

<xsl:template match="response"> 
    <xsl:apply-templates select="results"/> 
</xsl:template> 
+0

네, 그 트릭을 너무 오래 할 것입니다. 루트 요소는 항상 응답하기 때문에 기본 템플릿은 더 이상 xsl : apply-templates를 호출하지 않습니다. 템플릿의 추가 개발에는 xsl : apply-templates 명령이 포함될 가능성이 있으므로 안전하지 않습니다. –

+0

작동합니다. .NET을 통해 처리 할 때이 오류가 발생합니다. "상태 EndRootElement의 Token StartElement가 잘못된 XML 문서 ment. XML 조각을 작성하려면 ConformanceLevel 설정이 ConformanceLevel.Fragment 또는 ConformanceLevel.Auto로 설정되어 있는지 확인하십시오. System.InvalidOperationException "관련이 있습니까? –

+0

아마도 XML 형식이 잘못되었습니다. 현재 XML 출력을 표시하면 –

0

당신은 단지 하나의 정합 가능한 템플릿을 가지고있다. 그래서 그것과 일치하지 않는 모든 것은 XSLT 내장 템플릿에 의해 처리됩니다.

다른 요소에 대한 추가 템플릿을 만들어야합니다. 이게 뭔가 ...

<xsl:template match="*" /> 

... 다른 템플릿과 구체적으로 일치하지 않는 요소는 모두 가라 앉습니다.

+0

XSLT newb로서이 문제에 대해 좀 더 설명해 줄 수 있습니까? 마지막 템플리트로 지정한 것을 넣으려고했지만 아무 것도 출력되지 않았습니다. 내 주어진 답변에 대한 귀하의 의견을 추측, 나는이 솔루션을 어쩌면 더 나은 접근법을 의심? –

+0

XSLT 도움말을 얻는 가장 좋은 방법은 다음을 지정하는 것입니다. (1) XLST 버전 및 프로세서. (2) 적어도 하나의 좋은 유스 케이스; (3) 유스 케이스에 의해 암시되지 않는 변형 규칙을 정의하는 내러티브. 유스 케이스는 간단한 샘플 문서이며, 엣지 케이스의 적용 범위와 일치하는 예상 출력 문서입니다. –

관련 문제