XSL selecting variable tag

Viewed 33

I have a simple XML file where I want to extract the "name" from the instances of filecomp status="diff". The attached XML is an example of the two variables I need to be sorted out and my XSL that doesn't work :(

<report>
<foldercomp>
<filecomp status="same">        
    <lt>    
        <name>abc.pdf</name>
        <size>1,911,353</size>
        <modified>2/10/2021 8:25:08 AM</modified>
    </lt>   
    <rt>    
        <name>abc.pdf</name>
        <size>1,911,353</size>
        <modified>2/10/2021 8:45:17 AM</modified>
    </rt>   
</filecomp>     
<filecomp status="diff">        
    <lt>    
        <name>xyz.pdf</name>
        <size>671,735</size>
        <modified>2/10/2021 8:25:08 AM</modified>
    </lt>   
    <rt>    
        <name>xyz.pdf</name>
        <size>663,888</size>
        <modified>2/10/2021 8:45:17 AM</modified>
    </rt>   
</filecomp>     
</foldercomp>
</report>

XSLT so far:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <h2>Cards</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>cards</th>
      </tr>

    <xsl:for-each select="filecomp ['status=diff']">
<tr>
    <td><xsl:value-of select="name"/></td>
        </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>
1 Answers

I want to extract the "name" from the instances of <filecomp status="diff">

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
    <body>
      <h2>Cards</h2>
      <table border="1">
        <tr bgcolor="#9acd32">
          <th>cards</th>
        </tr>
        <xsl:apply-templates select="filecomp[@status='diff']" />
      </table>
    </body>
    </html>
  </xsl:template>

  <xsl:template match="filecomp">
    <tr>
      <td><xsl:value-of select="lt/name"/></td>
    </tr>
  </xsl:template>
</xsl:stylesheet>
Related