我对一些XSLT和Umbraco提出了一个小挑战。
这是一个"功能"输出招聘广告。
我必须从X节点中选择最多3个节点(作业广告),并且我想要选择这3个节点中的两个X类型和一个Y类型。
我有一个名为jobAdType
的属性别名,我想选择两个拥有jobAdType= Vikar
的节点和一个拥有jobAdType= Fast job
的节点。广告类型是从Umbraco的下拉列表中选择的。
广告的XML是:
<FrontPageAd id="1379" parentID="1246" level="3" creatorID="0" sortOrder="0" createDate="2014-11-07T11:40:14" updateDate="2014-11-12T09:09:55" nodeName="Annonce 1" urlName="annonce-1" path="-1,1058,1246,1379" isDoc="" nodeType="1245" creatorName="ITSecurity" writerName="ITSecurity" writerID="0" template="0" nodeTypeAlias="FrontPageAd">
<adHeader>Headr</adHeader>
<adBodyText>jkdjdk</adBodyText>
<adCompany>Test firma</adCompany>
<adPosition>Test stilling</adPosition>
<adCompanyLogo>
<MultiNodePicker type="media">
<nodeId>1317</nodeId>
</MultiNodePicker>
</adCompanyLogo>
<jobAdType>Vikar</jobAdType>
</FrontPageAd>
当前的XSLT是这样的:
<xsl:variable name="header" select="umbraco.library:GetDictionaryItem('Frontpage.Content.JobAdsHeader')" />
<xsl:if test="$adCount > 0">
<div class="jobAdsContainer">
<strong class="header uc"><xsl:value-of select="$header" /></strong>
<div class="container">
<div class="adslider">
<ul class="noList adList slideList">
<xsl:for-each select="$adIds [position() < 4]">
<xsl:variable name="adItem" select="umbraco.library:GetXmlNodeById(.)" />
<xsl:call-template name="JobTypeItem">
<xsl:with-param name="item" select="$adItem" />
</xsl:call-template>
</xsl:for-each>
</ul>
</div>
</div>
</div>
</xsl:if>
<xsl:variable name="companyLabel" select="umbraco.library:GetDictionaryItem('Frontpage.AdList.Company')" />
<xsl:variable name="positionLabel" select="umbraco.library:GetDictionaryItem('Frontpage.AdList.Position')" />
<xsl:variable name="contactPersonLabel" select="umbraco.library:GetDictionaryItem('Frontpage.AdList.ContactPerson')" />
<xsl:variable name="adType" select="$item/jobAdType" />
<xsl:variable name="adTitle" select="$item/@nodeName" />
<xsl:variable name="adHeader" select="$item/adHeader" />
<xsl:variable name="adBodyText" select="$item/adBodyText" />
<xsl:variable name="adCompany" select="$item/adCompany" />
<xsl:variable name="adPosition" select="$item/adPosition" />
<xsl:variable name="adLogo" select="$item/adCompanyLogo/descendant::nodeId" />
<li>
<xsl:if test="$adLogo != ''">
<div class="table">
<div class="adImage">
<xsl:variable name="image" select="umbraco.library:GetMedia($adLogo, 0)" />
<img src="{Eksponent.CropUp:Url($image/umbracoFile, '175x-M')}" />
</div>
</div>
</xsl:if>
<span class="header uc"><xsl:value-of select="$adHeader" /></span>
<span class="company"><strong><xsl:value-of select="$companyLabel" />:</strong> <xsl:value-of select="concat(' ', $adCompany)" /></span>
<span class="position"><strong><xsl:value-of select="$positionLabel" />:</strong> <xsl:value-of select="concat(' ', $adPosition)" /></span>
<span class="description">
<xsl:value-of select="$adBodyText" disable-output-escaping="yes" />
</span>
</li>
答案 0 :(得分:1)
您可以使用&#34; apply-templates&#34;而不是每个人:
<xsl:for-each select="$adIds [position() < 4]">
<!-- Is this .net call necessary? Is . another node other then the current one? -->
<xsl:variable name="adItem" select="umbraco.library:GetXmlNodeById(.)" />
<xsl:call-template name="JobTypeItem">
<xsl:with-param name="item" select="$adItem" />
</xsl:call-template>
</xsl:for-each>
然后限制select语句中的节点:
<xsl:apply-templates select="FrontPageAd[position() < 3][string(./jobAdType) = 'Vikar']"/>
<xsl:apply-templates select="FrontPageAd[position() < 2][string(./jobAdType) = 'Fast job']"/>
然后添加与FrontPageAd匹配的模板
<xsl:template match="FrontPageAd">
<!-- add code goes here. -->
</xsl:template>