In the below XSL every time the xsl:when gets satisfied I want to append as many <a
> and </a
> tags. But the data that needs to be populated inside the tags should be only once. I have shown the expected output at the end.
<xsl:param name="insert-file" as="document-node()" />
<xsl:template match="*">
<xsl:variable name="input">My text</xsl:variable>
<xsl:variable name="Myxml" as="element()*">
<xsl:call-template name="populateTag">
<xsl:with-param name="nodeValue" select="$input"/>
</xsl:call-template>
</xsl:variable>
<xsl:copy-of select="$Myxml"></xsl:copy-of>
</xsl:template>
<xsl:template name="populateTag">
<xsl:param name="nodeValue"/>
<xsl:for-each select="$insert-file/insert-data/data">
<xsl:choose>
<xsl:when test="@index = 1">
<a><xsl:value-of select="$nodeValue"></xsl:value-of></a>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
Current output:
<?xml version="1.0" encoding="UTF-8"?
>
<a
>My text</a
>
<a
>My text</a
>
<a
>My text</a
>
<a
>My text</a
>
I want the template "populateTag" to return me the xml in the below format. How do i modify the template "populateTag" to achive the same.
Expected output from template "populateTag":
<?xml version="1.0" encoding="UTF-8"?
>
<a
><a
><a
><a
>My text</a
></a
></a
></a
>
Please give your ideas.