Mega Code Archive

 
Categories / XML / XSLT StyleSheet
 

Branching

File: Data.xml <?xml version="1.0" standalone="no" ?> <transcript>   <student id="STU12345" name="name 1" status="active">     <home_address>35 Wall Street, Wonderland, NJ</home_address>     <interests>       <interest>interest 1</interest>       <interest>interest 2</interest>       <interest>interest 3</interest>     </interests>   </student>   <term>     <heading name="Winter 1999" />     <course>       <course-name>course 1</course-name>       <grade>A-</grade>       <credits>4</credits>     </course>     <course>       <course-name>course 2</course-name>       <grade>A</grade>       <credits>3</credits>     </course>   </term>   <summary>summary</summary>   <comments>     comments   </comments> </transcript> File: Transform.xslt <?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">   <xsl:template match="transcript">     Student received A's in the following courses:     <xsl:apply-templates       select="term/course[starts-with(grade,'A')]" />   </xsl:template>   <xsl:template match="course">     <xsl:value-of select="course-name" />     <xsl:if test="not(position()=last())">,</xsl:if>   </xsl:template> </xsl:stylesheet> Output: <?xml version="1.0" encoding="UTF-8"?>     Student received A's in the following courses:     course 1,course 2