deepan
deepan

Reputation: 47

how to call one match inside another match in xsl file

input :

firstdto:

  1. link : google.com
  2. name: google

seconddto

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

output expected :

google.com
yahoo.com
google

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

output current:

google.com
google.com
google

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>

Upvotes: 0

Views: 197

Answers (1)

sspsujit
sspsujit

Reputation: 301

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

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>

to get output like:

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

Upvotes: 1

Related Questions