如何在 xsl 文件中的另一个匹配项中调用一个匹配项 [英] how to call one match inside another match in xsl file

查看:27
本文介绍了如何在 xsl 文件中的另一个匹配项中调用一个匹配项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入:

先到:

  1. 链接:google.com
  2. 名称:谷歌

第二次

  1. 链接:yahoo.com
  2. 名称:雅虎

<sites>
  <firstdto>
    <link>google.com</link>
    <name>google</name>
  </firstdto>
  <seconddto>
    <link>yahoo.com</link>
    <name>yahoo</name>
  </seconddto>
</sites>

预期输出:

google.com
yahoo.com
google

<body>
 <link>google.com</link>
 <link>yahoo.com</link>
 <name>google</name>
</body>

输出电流:

google.com
google.com
google

注意:我只想在 firstdto 中导入 seconddto 函数.因为我想在第一个属性中使用 seconddto 属性.但我无法做到这一点.即使我将模板与 seconddto 匹配,它仍然从 firstdto 获取链接.

Note: I just want to import seconddto function inside firstdto. Because i want to use seconddto attributes inside first attributes. But i am not able to achieve that. It still gets link from firstdto even if i matched my template to seconddto.

有人可以帮我解决这个问题吗?这对我真的很有帮助.提前致谢.

Can someone help me with this. It would be really helpful for me. Thanks in advance.

<xsl:stylesheet>
<Xsl:template match="/">
<head>
<style>
  .....
</style>
</head>
<body>
<xsl:apply-templates select="firstdto"/>
<xsl:apply-templates select="seconddto"/>
</body>
</xsl:template>

<xsl:template match="firstdto">
   <body>
     <xsl:value-of select="link"/>
       <xsl:template match="seconddto">
        <body>
          <xsl:value-of select="link"/>
        </body>
       </xsl:template>
     <xsl:value-of select="name">
   </body>
</xsl:template>

推荐答案

我只想在 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>

这篇关于如何在 xsl 文件中的另一个匹配项中调用一个匹配项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆