Dec 22, 2008

XSLT note 3 - attribute tricks

When you want to output the value of node to destination, you can use . This works only when the destination is not in side of an attribute. If the output is in side of an attribute, you need to use {}. For example.


ascending

  
    
  



   

If you want to output a attribute of source element, you need to use @attributeName, or attribute::attributeName.

To add an attribute to an output node, you can also use xsl:attribute, like the following.

  
    
      http://google.com
      Google
    
  

Some time we want to convert element to attribute. For example, we want to convert


  Fred
  18



We can use this template


  
    
      
        
      
    
  


or