Search code examples
xsltxslt-1.0biztalkbiztalk2006r2biztalk-mapper

Biztalk Map node validation


I'm mapping home, work and mobile number nodes from the source schema to the home, work and mobile node in the destination schema.

I need to ensure that the data matches destination pattern (No space, punctuation, leading zeros, matching [+0][0-9]*. Can this be achieved via XSLT?

Source

<HTelephone>01656 123 123</HTelephone>
<WTelephone>01656-123-123</WTelephone>
<MTelephone>+447656 123 123</MTelephone>

Destination

<HTelephone>01656123123</HTelephone>
<WTelephone>01656123123</WTelephone>
<MTelephone>+447656123123</MTelephone>

Current Inline XSLT Call Template

<xsl:template name="MNo" xmlns:msxsl="urn:schemas-microsoft-com:xslt" >
 <xsl:param name="inTelNo"/>
 <xsl:element name="MTelephone" >
     <xsl:value-of select="concat('+', translate($inTelNo, translate($inTelNo,'0123456789',''), ''))"/>
 </xsl:element>

We need to validation the first character to allow a 0 or + also, any ideas?


Solution

  • Assuming correct input ( a root element to make it well-formed XML) use the concat() and translate functions to change the strings.

    Input

    <?xml version="1.0" encoding="utf-8"?>
    <root>
        <HTelephone>01656 123 123</HTelephone>
        <WTelephone>01656 123 123</WTelephone>
        <MTelephone>01656 123 123</MTelephone>
    </root>
    

    Stylesheet

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
    
        <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
        <xsl:strip-space elements="*"/>
    
        <xsl:template match="/root">
            <xsl:copy>
                <xsl:apply-templates/>
            </xsl:copy> 
        </xsl:template>
    
        <xsl:template match="root/*">
            <xsl:copy>
                <xsl:value-of select="concat('+',translate(.,' ',''))"/>
            </xsl:copy>
        </xsl:template>
    
    </xsl:stylesheet>
    

    Output

    <?xml version="1.0" encoding="utf-8"?>
    <root>
       <HTelephone>+01656123123</HTelephone>
       <WTelephone>+01656123123</WTelephone>
       <MTelephone>+01656123123</MTelephone>
    </root>