繁体   English   中英

使用XSLT和Umbraco选择特定别名的最大项

[英]Selection max items of specific aliases with XSLT and Umbraco

对于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 &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>

您可以使用“ apply-templates”代替每个for:

<xsl:for-each select="$adIds [position() &lt; 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() &lt; 3][string(./jobAdType) = 'Vikar']"/>
<xsl:apply-templates select="FrontPageAd[position() &lt; 2][string(./jobAdType) = 'Fast job']"/>

然后添加与FrontPageAd匹配的模板

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM