如何使用XSLT创建不同的值

我有这样的XML:


<items>

  <item>

    <products>

      <product>laptop</product>

      <product>charger</product>

    </products>

  </item>

  <item>

    <products>

      <product>laptop</product>

      <product>headphones</product>  

    </products>  

  </item>

</items>

我希望它输出像


笔记本电脑

充电器

头戴式耳机

我正在尝试使用,distinct-values()但我想我做错了什么。谁能告诉我如何使用distinct-values()?谢谢。


<xsl:template match="/">            

  <xsl:for-each select="//products/product/text()">

    <li>

      <xsl:value-of select="distinct-values(.)"/>

    </li>               

  </xsl:for-each>

</xsl:template>

但是它给了我这样的输出:


<li>laptop</li>

<li>charger</li>

<li>laptop></li>

<li>headphones</li>


子衿沉夜
浏览 485回答 3
3回答

缥缈止盈

您不希望“输出(不同的值)”,而想要“对于每个(不同的值)”:<xsl:template match="/">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; <xsl:for-each select="distinct-values(/items/item/products/product/text())">&nbsp; &nbsp; <li>&nbsp; &nbsp; &nbsp; <xsl:value-of select="."/>&nbsp; &nbsp; </li>&nbsp; </xsl:for-each></xsl:template>
打开App,查看更多内容
随时随地看视频慕课网APP