Reputation: 2113
I have a small challenge with some XSLT and Umbraco.
It is a "function" to output job adverts.
I have to select a maximum of 3 nodes (job adverts) out X nodes and with those 3 nodes I want to select two of X type and one of Y type.
I have a property alias called jobAdType
and I want to select two nodes that have jobAdType= Vikar
and one node that have jobAdType= Fast job
. Ad type is selected from a drop-down in Umbraco.
The XML of an adverts is:
<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>
The current XSLT is this:
<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>
Upvotes: 1
Views: 128
Reputation: 667
You can use "apply-templates" instead of this for-each:
<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>
Then limit the nodes in the select statement:
<xsl:apply-templates select="FrontPageAd[position() < 3][string(./jobAdType) = 'Vikar']"/>
<xsl:apply-templates select="FrontPageAd[position() < 2][string(./jobAdType) = 'Fast job']"/>
Then add a template that matches FrontPageAd
<xsl:template match="FrontPageAd">
<!-- add code goes here. -->
</xsl:template>
Upvotes: 1