XSLT generate-id() 函数


定义和用法

generate-id() 函数返回唯一标识指定节点的字符串值。

如果指定的节点集是空的,则返回空字符串。如果省略了 node-set 参数,则默认设置为当前节点。


语法

  1. string generate-id(node-set?)
参数
参数描述
node-set可选。规定生成哪个节点集的唯一 id。

例子

  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <xsl:stylesheet version="1.0"
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4. <xsl:template match="/">
  5. <html>
  6. <body>
  7. <h3>Artists:</h3>
  8. <ul>
  9. <xsl:for-each select="catalog/cd">
  10. <li>
  11. <a href="#{generate-id(artist)}">
  12. <xsl:value-of select="artist" /></a>
  13. </li>
  14. </xsl:for-each>
  15. </ul>
  16. <hr />
  17. <xsl:for-each select="catalog/cd">
  18. Artist: <a name="{generate-id(artist)}">
  19. <xsl:value-of select="artist" /></a>
  20. <br />
  21. Title: <xsl:value-of select="title" />
  22. <br />
  23. Price: <xsl:value-of select="price" />
  24. <hr />
  25. </xsl:for-each>
  26. </body>
  27. </html>
  28. </xsl:template>
  29. </xsl:stylesheet>

查看 XML 文件查看 XSL 文件查看结果

分类导航