0

我正在学习 xml 和 XSLT。

我想创建 XSLT 文件,它可以显示 family.xml 文件中的所有名称

我有...

doc("family.xml")//名称

但是,我不确定在 XSLT 文件上使用 doc 函数的语法。

有人可以帮助我吗?

谢谢

4

1 回答 1

1

假设您的 filename.xml 就像:

<?xml version="1.0"?>
<bookstore>
  <book category="COOKING">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
  </book>
  <book category="CHILDREN">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
  <book category="WEB">
    <title lang="en">Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </book>
</bookstore>

获取所有标题:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">

<!-- match root documents tag -->
<xsl:template match="/">
<xsl:apply-templates select="document('filename.xml')/bookstore//title/node()" mode="document"/>
</xsl:template>


  <xsl:template match="/" mode="document">
    <xsl:copy-of select="."/>
  </xsl:template>

</xsl:stylesheet>
于 2013-02-15T01:22:25.520 回答