我正在尝试学习 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&qd=Cg_V6UykGXt-ccaEWxs0BA1LyorWd-7Tcbya1NtZKa9WZ1DtngXSHw91EGjVCy_rntA_Y_5cpbSuoLd44_xEjXNG-vBD0DC792zHqZRp6lE&indpubnum=1813651566614396&atk=179li835k18b17ae</url>
<onmousedown>indeed_clk(this, '5585');</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&qd=Cg_V6UykGXt-ccaEWxs0BA1LyorWd-7Tcbya1NtZKa9WZ1DtngXSHw91EGjVCy_rntA_Y_5cpbSuoLd44_xEjXNG-vBD0DC792zHqZRp6lE&indpubnum=1813651566614396&atk=179li835k18b17ae</url>
<onmousedown>indeed_clk(this, '5585');</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()<=$ItemsToShow or $ItemsToShow<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&qd=Cg_V6UykGXt-ccaEWxs0BA1LyorWd-7Tcbya1NtZKa9WZ1DtngXSHw91EGjVCy_rntA_Y_5cpbSuoLd44_xEjXNG-vBD0DC792zHqZRp6lE&indpubnum=1813651566614396&atk=179li835k18b17ae" target="" onclick="_gaq.push(['_trackEvent','indeed.com','none','http://www.indeed.com/viewjob?jk=06bef17e206740d3&qd=Cg_V6UykGXt-ccaEWxs0BA1LyorWd-7Tcbya1NtZKa9WZ1DtngXSHw91EGjVCy_rntA_Y_5cpbSuoLd44_xEjXNG-vBD0DC792zHqZRp6lE&indpubnum=1813651566614396&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&qd=Cg_V6UykGXt-ccaEWxs0BA1LyorWd-7Tcbya1NtZKa9WZ1DtngXSHw91EGjVCy_rntA_Y_5cpbSuoLd44_xEjXNG-vBD0DC792zHqZRp6lE&indpubnum=1813651566614396&atk=179li835k18b17ae" target="" onclick="_gaq.push(['_trackEvent','indeed.com','none','http://www.indeed.com/viewjob?jk=a17a7c578a779db8&qd=Cg_V6UykGXt-ccaEWxs0BA1LyorWd-7Tcbya1NtZKa9WZ1DtngXSHw91EGjVCy_rntA_Y_5cpbSuoLd44_xEjXNG-vBD0DC792zHqZRp6lE&indpubnum=1813651566614396&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>