0

Hello,

I am quite new with XSLT and I need to convert this xml:

<?xml version="1.0" standalone="yes"?>
<assesmentItem>
<choiceInteraction responseIdentifier="correctresponse" title="title" discipline="discipline1" dificulty="dificulty1" timexpected="20" basetype="choice" cardinality="single">
<prompt>answer1</prompt>
<simplechoice0 >response0</simplechoice0>
<simplechoice1 >response1</simplechoice1>
<simplechoice2>response2</simplechoice2>
</choiceInteraction>

</assesmentItem>

into this one:


<?xml version="1.0" standalone="yes"?>
<assesmentItem>

<choiceInteraction responseIdentifier="correctresponse" title="title" discipline="discipline1" dificulty="dificulty1" timexpected="20" basetype="choice" cardinality="single">

<prompt>answer1</prompt>
<simplechoice identifier="choiceA">response1</simplechoice>
<simplechoice identifier="choiceB">response2</simplechoice>
<simplechoice identifier="choiceC">response3</simplechoice>
</choiceInteraction>

</assesmentItem>

Where identifier choiceA would be added for the element simplechoice0 and so on with the others. I have to do the conversion and then the inversion but that one I already have it tough my problem is to do this conversion of attributes and elements.

Thanks so much for your help

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by gravyboat
0
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
    	<assesmentItem>
			<xsl:apply-templates/>
		</assesmentItem>
    </xsl:template>
    
    <xsl:template match="choiceInteraction">
    	<choiceInteraction>
    	    <xsl:copy-of select="@*"/>
		    <xsl:copy-of select="./prompt"/>
		    <xsl:apply-templates/>
    	</choiceInteraction>
    </xsl:template>
    
    <xsl:template match="simplechoice0">
		<simplechoice identifier="choiceA">
			<xsl:value-of select="."/>
		</simplechoice>
    </xsl:template>
    
    <xsl:template match="simplechoice1">
		<simplechoice identifier="choiceB">
			<xsl:value-of select="."/>
		</simplechoice>
    </xsl:template>
    
    <xsl:template match="simplechoice2">
		<simplechoice identifier="choiceC">
			<xsl:value-of select="."/>
		</simplechoice>
    </xsl:template>

	<xsl:template match="text()"/>
</xsl:stylesheet>

If you want the text of the simplechoice elements to change (e.g,. from 'response0' to 'response1') just replace the <xsl:value-of select statement with the actual text you want in each template.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.