0
votes

Hi I'm having the below input xml file:

<Description>Same Date <Text>True</Text></Description>

XSL I have tried for

<xsl:template match="Description">
    <def>
        <para>
            <title>
                <xsl:value-of select="Description"/>
            </title>
            <para>
                <xsl:value-of select="Text"/>
            </para>
        </para>
    </def>
</xsl:template>

Expected Output:

<def>
    <para>
        <title>Same Date</title>
        <para>True</para>
    </para>
 </def>

I need to split the child element and change into seperate element.

2

2 Answers

0
votes

You can try This:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:output method="xml" omit-xml-declaration="no"/>
    <xsl:template match="Description">
        <def>
            <para>
                <title>
                    <xsl:value-of select="normalize-space(node()[1])"/>
                </title>
                <xsl:if test="Text">
                    <para>
                        <xsl:value-of select="Text"/>
                    </para>
                </xsl:if>
            </para>
        </def>
    </xsl:template>
</xsl:stylesheet>
0
votes

Change Following Code:-

<title><xsl:value-of select="Description"/></title>

to

<title><xsl:value-of select="normalize-space(substring-before(., Text))"/></title>