I'm using XSLT to transform XML that I'm receiving from a webservice. What I've got is something like this:
<benefit>
<statusReasonCode1>Code</statusReasonCode1>
<statusReason1>Reason</statusReason1>
<otherStuff1>blah</otherStuff1>
<otherStuff2>blah</otherStuff2>
</benefit>
What I want is this:
<benefit>
<statusReasonCode1>Code</statusReasonCode1>
<statusReason1>Reason</statusReason1>
<statusReasonText1>Code - Reason></statusReasonText1>
<otherStuff1>blah</otherStuff1>
<otherStuff2>blah</otherStuff2>
</benefit>
What I'm getting is this:
<benefit>
<statusReasonCode1>Code</statusReasonCode1>
<statusReason1>Reason</statusReason1>
<otherStuff1>blah</otherStuff1>
<otherStuff2>blah</otherStuff2>
<statusReasonText1>Code - Reason></statusReasonText1>
</benefit>
This is the xslt that's doing it:
<xsl:template match=''benefit''>
<xsl:copy use-attribute-sets=''newBenefit''>
<xsl:apply-templates/>
<statusReasonCodeText1><xsl:value-of select="statusReasonCode1"/><xsl:text> - </xsl:text><xsl:value-of select="statusReason1"/></statusReasonCodeText1>
</xsl:copy>
</xsl:template>
Is there a way that I can specify location when creating an element?
If the new element always has to be inserted after
statusReason1
then you could do:You could do:
There are other ways depending on what you know about your input, as well as which version of XSLT you're using.
Added:
You can add them using:
or: