1 <?xml version="1.0" encoding="utf-8"?> 2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 3 version="1.0"> 4 5 <!-- Restructure questions. --> 6 7 <xsl:template match="question"> 8 <xsl:copy> 9 <xsl:if test="@selected"> 10 <xsl:element name="response"> 11 <xsl:apply-templates select="@selected"/> 12 <xsl:for-each select="choice[position() = number(current()/@selected)]"> 13 <xsl:if test="not(response-type/@value = 'choice')"> 14 <xsl:apply-templates select="@response-text"/> 15 </xsl:if> 16 </xsl:for-each> 17 </xsl:element> 18 </xsl:if> 19 <xsl:apply-templates select="choice"/> 20 </xsl:copy> 21 </xsl:template> 22 23 <xsl:template match="choice"> 24 <xsl:if test="@selected = 'true' or response-type/@value='text'"> 25 <xsl:element name="response"> 26 <xsl:attribute name="selected"><xsl:value-of select="position()"/></xsl:attribute> 27 <xsl:if test="not(response-type/@value = 'choice')"> 28 <xsl:apply-templates select="@response-text"/> 29 </xsl:if> 30 </xsl:element> 31 </xsl:if> 32 </xsl:template> 33 34 35 36 <!-- Replicate unknown elements. --> 37 38 <xsl:template match="@*|node()"> 39 <xsl:copy> 40 <xsl:apply-templates select="@*|node()"/> 41 </xsl:copy> 42 </xsl:template> 43 44 </xsl:stylesheet>