0

I am using XSLT

Input is like below

<data>
    <details>
        <DATA>
            <name>nameValue</name>
        </DATA>
        <DATA>
            <name>nameValue1</name>
        </DATA>
    <details>
<data>

XSLT is

<xsl:template match="details">
    <xsl:copy>
        <info>
            <person_name>
                <xsl:value-of select="DATA/name"/>
            </person_name>
        </info>
    </xsl:copy>
</xsl:template>

output

<info>
    <person_name>nameValue</person_name>
</info>

Expected output is like below

<info>
    <person_name>nameValue</person_name>
</info>
<info>
    <person_name>nameValue1</person_name>
</info>

1 Answer 1

2

Your XML is not well-formed, as it has opening tag where closing tags should be. But assuming it looked like this...

<data>
    <details>
        <DATA>
            <name>nameValue</name>
        </DATA>
        <DATA>
            <name>nameValue1</name>
        </DATA>
    </details>
</data>

... what you need to do is use an xsl:for-each to select each child DATA element

<xsl:template match="details">
    <xsl:copy>
        <xsl:for-each select="DATA">
            <info>
                <person_name>
                    <xsl:value-of select="name"/>
                </person_name>
            </info>
        </xsl:for-each>
    </xsl:copy>
</xsl:template>
Sign up to request clarification or add additional context in comments.

3 Comments

I update question its like data is root element then details and then DATA
By using this XSLT I am getting blank details node. I used xsl:for-each select="details"
I've amended my answer to handle your new XML structure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.