Search code examples
xsltxslt-2.0

I need Recursive function for below XML


<Root><TID>E</TID><EID>1234</EID><Name>suresh</Name><OID>12</OID></Root>

I need XSLT for above XML. Tips: output fixed length:

  • TID is (1)
  • EID(2-10)
  • Filler(11-13)
  • Name(14-20)
  • OID (21-24)

Output will be:

E000001234   Suresh 0012

Number should be filled with 0000, string left padding remaining with spaces - Filler also space

Some one could you please help me on this


Solution

  • I would do simply:

    <xsl:template match="/Root">
        <xsl:value-of select="TID"/>
        <xsl:value-of select="format-number(EID, '000000000')"/>
        <xsl:text>   </xsl:text>
        <xsl:value-of select="substring(concat(Name, '       '), 1, 7)"/>
        <xsl:value-of select="format-number(OID, '0000')"/>
    </xsl:template>