且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 xsl 文件中的另一个匹配项中调用一个匹配项

更新时间:2023-02-22 11:37:36

我只想在 firstdto 中导入 seconddto 函数.因为我想在第一个属性中使用 seconddto 属性.

I just want to import seconddto function inside firstdto. Because i want to use seconddto attributes inside first attributes.

如果你想在 firstdto 中使用 seconddto 的值,那么你可以试试这个:

If you want to use value from seconddto inside firstdto, then you can try this:

<xsl:template match="/sites">
  <html>
    <head>
        <style>.....</style>
    </head>
    <body>
        <xsl:apply-templates select="firstdto"/>
    </body>
  </html>  
</xsl:template>

<xsl:template match="firstdto">
  <xsl:copy-of select="link"/>
  <xsl:copy-of select="../seconddto/link"/><!-- to use/copy value from other -->
  <xsl:copy-of select="name"/>
</xsl:template>

得到如下输出:

<html>
 <head>
  <style>.....</style>
 </head>
 <body>
  <link>google.com</link>
  <link>yahoo.com</link>
  <name>google</name>
 </body>
</html>