Saturday 15 June 2013

html - Selection max items of specific aliases with XSLT and Umbraco -



html - Selection max items of specific aliases with XSLT and Umbraco -

i have little challenge xslt , umbraco.

it "function" output job adverts.

i have select maximum of 3 nodes (job adverts) out x nodes , 3 nodes want select 2 of x type , 1 of y type.

i have property alias called jobadtype , want select 2 nodes have jobadtype= vikar , 1 node have jobadtype= fast job. advertisement type selected drop-down in umbraco.

the xml of 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 this:

<xsl:variable name="header" select="umbraco.library:getdictionaryitem('frontpage.content.jobadsheader')" /> <xsl:if test="$adcount &gt; 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() &lt; 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>

you can utilize "apply-templates" instead of for-each:

<xsl:for-each select="$adids [position() &lt; 4]"> <!-- .net phone call necessary? . node other 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 nodes in select statement:

<xsl:apply-templates select="frontpagead[position() &lt; 3][string(./jobadtype) = 'vikar']"/> <xsl:apply-templates select="frontpagead[position() &lt; 2][string(./jobadtype) = 'fast job']"/>

then add together template matches frontpagead

<xsl:template match="frontpagead"> <!-- add together code goes here. --> </xsl:template>

html xml xslt xpath umbraco

No comments:

Post a Comment