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>
4

2 に答える 2

0

ああ、このリンクを見つけました

不要なものを除外するためにこれを追加しました:

<xsl:template match="response">
    <xsl:apply-templates select="results"/>
</xsl:template>
于 2012-10-17T00:03:28.487 に答える
0

一致するテンプレートは1つだけです。したがって、それと一致しないものはすべて、XSLTの組み込みテンプレートによって処理されます。

他の要素用に追加のテンプレートを作成する必要があります。このようなもの...

<xsl:template match="*" />

...他のテンプレートと特に一致しないすべての要素をシンクします。

于 2012-10-17T00:08:50.827 に答える