如何使用xsl:sort来排序图像,而不是基于position()

时间:2012-10-02 10:21:40

标签: html xslt xslt-1.0 xslt-2.0 visual-web-developer

已编辑:以下附加信息

我正在尝试使用< xsl:sort >按升序对图像进行排序无需使用“位置()函数。

我在使用< xsl:sort >时遇到问题用于按升序对图像进行排序。

这是我的XML输入代码,链接到产品 ASAMSCM195265783.jpg

             <objectImage code="ASAMSCM195265783" name="NX1000 Compact System Camera in White with 20-50mm Lens Product Image (Primary)" imageTypeName="Product Image" imageTypeCode="PRODUCT" objectTypeImageCode="PRIMARY_PRODUCT" objectTypeImageName="Primary Product Image" displayOrder="7">
                 <imageVersions>
                    <imageVersion versionTypeCode="PRODUCT_THUMB_SM" width="15" height="15" path="PRODUCT/PRODUCT_THUMB_SM/ASAMSCM195265783.jpg" link=""/>
                    <imageVersion versionTypeCode="PRODUCT_THUMB_M" width="32" height="32" path="PRODUCT/PRODUCT_THUMB_M/ASAMSCM195265783.jpg" link=""/>
                    <imageVersion versionTypeCode="PRODUCT_REGULAR" width="170" height="170" path="PRODUCT/PRODUCT_REGULAR/ASAMSCM195265783.jpg" link=""/>
                    <imageVersion versionTypeCode="PRODUCT_ENLARGED" width="500" height="500" path="PRODUCT/PRODUCT_ENLARGED/ASAMSCM195265783.jpg" link=""/>
                    <imageVersion versionTypeCode="PRODUCT_THUMB_L" width="36" height="36" path="PRODUCT/PRODUCT_THUMB_L/ASAMSCM195265783.jpg" link=""/>
                    <imageVersion versionTypeCode="PRODUCT_THUMB_XL" width="150" height="150" path="PRODUCT/PRODUCT_THUMB_XL/ASAMSCM195265783.jpg" link=""/>
                    <imageVersion versionTypeCode="PRODUCT_THUMB_110" width="110" height="110" path="PRODUCT/PRODUCT_THUMB_110/ASAMSCM195265783.jpg" link=""/>
                    <imageVersion versionTypeCode="PRODUCT_LARGE" width="300" height="300" path="PRODUCT/PRODUCT_LARGE/ASAMSCM195265783.jpg" link=""/>
                    <imageVersion versionTypeCode="PRODUCT_THUMB_50x50" width="50" height="50" path="PRODUCT/PRODUCT_THUMB_50x50/ASAMSCM195265783.jpg" link=""/>
                    <imageVersion versionTypeCode="PRODUCT_THUMB_75x75" width="75" height="75" path="PRODUCT/PRODUCT_THUMB_75x75/ASAMSCM195265783.jpg" link=""/>
                  </imageVersions>
             </objectImage>

我对其他 ASAMSCM195265783.jpg 产品的其他XML示例与上述完全相同,但只有 objectTypeImageCode =“OTHER_PRODUCT”而不是 PRIMARY_PRODUCT displayOrder =“8”“9”

这是我目前的XSLT代码:

<xsl:sort select="displayOrder" data-type="number" order="descending"/>
            <li class="prodthumbimg">
              <a>
                <xsl:attribute name="id">
                  <xsl:text>thumb</xsl:text>
                  <xsl:value-of select="position()" />

以下是HTML中的结果:

<li class="prodthumbimg"><a id="thumb10" href="javascript:void(swap(9));" target=""><img src="http://www.jessops.com/ce-images/PRODUCT/PRODUCT_THUMB_50x50/ASAMSCM195265783_009.jpg" alt="Samsung NX1000 Compact System Camera in White with 20-50mm Lens" title="Samsung NX1000 Compact System Camera in White with 20-50mm Lens"></a></li>

<li class="prodthumbimg"><a id="thumb9" href="javascript:void(swap(8));" target=""><img src="http://www.jessops.com/ce-images/PRODUCT/PRODUCT_THUMB_50x50/ASAMSCM195265783.jpg" alt="Samsung NX1000 Compact System Camera in White with 20-50mm Lens" title="Samsung NX1000 Compact System Camera in White with 20-50mm Lens"></a></li>

<li class="prodthumbimg"><a id="thumb8" href="javascript:void(swap(7));" target=""><img src="http://www.jessops.com/ce-images/PRODUCT/PRODUCT_THUMB_50x50/ASAMSCM195265783_008.jpg" alt="Samsung NX1000 Compact System Camera in White with 20-50mm Lens" title="Samsung NX1000 Compact System Camera in White with 20-50mm Lens"></a></li>

请注意,在HTML结果的第二行,产品图片 ASAMSCM195265783.jpg 位置错误?我试图在HTML结果的第三行显示该图像。所以基本上第二和第三个html行需要交换,以便产品图像的名称可以按降序正确排序。

我使用的是:

<xsl:sort select="position()" data-type="number" order="descending"/>
        <li class="prodthumbimg">
          <a>
            <xsl:attribute name="id">
              <xsl:text>thumb</xsl:text>
              <xsl:value-of select="position()" />

它完成工作但仅基于位置()(产品编号),我尝试根据产品名称而不是产品名称中的数字执行此操作(如果这样做感)。 任何帮助将不胜感激,提前感谢(如果您需要进一步澄清或任何进一步的问题,请让我

这是我在HTML中的理想结果:

<li class="prodthumbimg"><a id="thumb10" href="javascript:void(swap(9));" target=""><img src="http://www.jessops.com/ce-images/PRODUCT/PRODUCT_THUMB_50x50/ASAMSCM195265783_009.jpg" alt="Samsung NX1000 Compact System Camera in White with 20-50mm Lens" title="Samsung NX1000 Compact System Camera in White with 20-50mm Lens"></a></li>

<li class="prodthumbimg"><a id="thumb9" href="javascript:void(swap(8));" target=""><img src="http://www.jessops.com/ce-images/PRODUCT/PRODUCT_THUMB_50x50/ASAMSCM195265783_008.jpg" alt="Samsung NX1000 Compact System Camera in White with 20-50mm Lens" title="Samsung NX1000 Compact System Camera in White with 20-50mm Lens"></a></li>

<li class="prodthumbimg"><a id="thumb8" href="javascript:void(swap(7));" target=""><img src="http://www.jessops.com/ce-images/PRODUCT/PRODUCT_THUMB_50x50/ASAMSCM195265783.jpg" alt="Samsung NX1000 Compact System Camera in White with 20-50mm Lens" title="Samsung NX1000 Compact System Camera in White with 20-50mm Lens"></a></li>

如果您认为有更多相关信息与此处发布更相关以进一步澄清此问题,请告诉我,谢谢。

1 个答案:

答案 0 :(得分:2)

我认为问题是 displayOrder objectImage 元素的属性,但您当前的排序是将其视为元素。您可能需要将其更改为以下

<xsl:sort select="@displayOrder" data-type="number" order="descending"/>

另请注意,这可能只是您问题中的拼写错误,您声明要“按升序排序图像”。如果是这种情况,您显然必须在上面的 xsl:sort

中将“降序”更改为“升序”