I am new to xsl. I want to transform an xml from,
<result name="response" numFound="1" start="0">
<doc>
<str name="q">what</str>
<arr name="suggestion">
<str>what1</str>
<str>what2</str>
</arr>
</doc>
</result>
to,
<result name="response" numFound="2" start="0">
<doc>
<str name="q">what</str>
<str name="suggestion">what1</str>
</doc>
<doc>
<str name="q">what</str>
<str name="suggestion">what2</str>
</doc>
</result>
I could extract the texts, "what1" and "what2" using,
<xsl:template match="/response/result[@name='response']">
<xsl:for-each select="./doc/arr[@name='suggestion']/str">
<xsl:value-of select="normalize-space(.)"/>
<xsl:value-of select="$endl"/>
</xsl:for-each>
</xsl:template>
But I don't know how to enclose the same into output xml format. Can anyone please help...
Additional feature:
Can anyone please tell if I could add a field to the output doc called <float name="score">
which would get incremented by 100 with each doc?
eg) output:
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">1</int>
<lst name="params">
<str name="indent">on</str>
<str name="q">"what"</str>
</lst>
</lst>
<result numFound="2" name="response" start="0">
<doc>
<str name="query">what</str>
<str>what1</str>
<float name="score">100</float>
</doc>
<doc>
<str name="query">what</str>
<str>what2</str>
<float name="score">200</float>
</doc>
<doc>
<str name="query">what</str>
<str>what3</str>
<float name="score">300</float>
</doc>
</result>
</response>
Can you please tell what function do I suppose to use?