【问题标题】:xslt separators with 'and' before the last itemxslt 分隔符在最后一项之前带有“和”
【发布时间】:2015-07-17 19:32:10
【问题描述】:

我有一个问题,我必须显示 courseName 奖项,用逗号分隔作为求职信。很好,我可以使用带有 , 分隔符的 for-each 代码来做到这一点。问题是我想在最后一个奖项之前插入和'和'字符串。而且我无法与它合二为一。任何帮助将不胜感激。

  I wish to apply for the above post. i have


这里是xml代码


<!-- educational history starts below-->
<school>    
    <education>     
        <fromYear> 2010 </fromYear>
        <toYear> 2014 </toYear>
        <courseName> Bachelor of Science in Physocology </courseName>
        <institution> The University of Dublin, Trinity College </institution>

    </education>

    <education>
        <fromYear> 2004 </fromYear>
        <toYear> 2010 </toYear>
        <institution> Cadbury College, Ballyknock, CoRoscommon </institution>
            <subject>English (A1),Irish (B2) , History (B2),French (B3)and Maths (B1)</subject>
    </education>
    <education>
        <institution> University of Dublin, Trinity College </institution>
        <courseName>Bachelor of Arts in Economics, June 2005 </courseName>
        <subjects> Firms and Development, Statistics, Applied Economics and International Economics </subjects>
    </education>
</school>

【问题讨论】:

  • 您是否已经设置了 XSLT 样式表? ——如果是,请张贴。您也可以发布预期的输出吗?

标签: xml xpath foreach xslt-1.0 separator


【解决方案1】:

所以:

  • 在 position=1 之前,不插入任何内容

  • 在 position=2..last()-1 之前,插入 ","

  • 在 position=last() 之前,插入 " 和 "

那是

<xsl:for-each select=".....">
  <xsl:choose>
   <xsl:when test="position()=1"/>
   <xsl:when test="position()=last()">, and </xsl:when>
   <xsl:otherwise>, </xsl:otherwise>
  </xsl:choose>
  <xsl:value-of select="."/>
</xsl:for-each>

【讨论】:

    猜你喜欢
    • 2012-12-21
    • 2015-01-11
    • 2012-08-01
    • 2018-02-23
    • 2017-02-08
    • 1970-01-01
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多