954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Formatting specific elements of an XML using XSLT

Here is an excerpt of my input xml. I need to create an exact copy of this xml with only one change – the value of the element should be formatted as a string of 5 characters – for example, in this case 1 should be replaced with “00001”. There are multiple occurrences of this element across the file. Any help would be appreciated.

<SuperRecord>
    <TransmissionData>
        <DocumentID>100</DocumentID>
        <CreatedDateTime>2011-02-22</CreatedDateTime>
    </TransmissionData>
    <ReportingParty>
        <RoutingID>234</RoutingID>
        <ReportedFinancialSummary>
            <FinancialType>DLSubsidized</FinancialAwardType>
            <FinancialYear>2011</FinancialAwardYear>
            <TotalCount>5</TotalCount>
            <TotalReported>13750.00</TotalReportedAward>
            <Index>
        	      <SSN>36523125</SSN>
               <BirthDate>1992-05-19-04:00</BirthDate>
               <LastName>TRU</LastName>
            </Index>
    <TEACH>
        <FinancialYear>2011</FinancialAwardYear>
        <strong><FinancialNumber>1</FinancialAwardNumber></strong>  
    </TEACH>
</SuperRecord>
vt123
Newbie Poster
3 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

You need something like 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="1.0">
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="FinancialNumber">
        <xsl:copy>
            <xsl:number value="." format="00001"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>


Cheers, John Bampton

JohnBampton
Newbie Poster
15 posts since Feb 2011
Reputation Points: 10
Solved Threads: 6
 

John - It works great. Thanks !!

vt

vt123
Newbie Poster
3 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You