Mega Code Archive

 
Categories / XML Tutorial / Xpath
 

Attributes can be processed in the same way as elements

File: Data.xml <?xml version="1.0" encoding="utf-8"?> <employee id="js0034">     Joe Smith </employee> File: Transform.xslt <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet       version="1.0"       xmlns:xsl="http://www.w3.org/1999/XSL/Transform">     <xsl:template match="employee">       <xsl:value-of select="."/>       <xsl:text>[</xsl:text>       <xsl:apply-templates select="@id"/>       <xsl:text>]</xsl:text>     </xsl:template>     <xsl:template match="@id">       <b>         <i>           <xsl:value-of select="."/>         </i>       </b>     </xsl:template> </xsl:stylesheet> Output: <?xml version="1.0" encoding="UTF-8"?>     Joe Smith [<b><i>js0034</i></b>]