i trying soap xml transformation in xslt.
i have field called "acctcd" under "externalidgroup" array. need check field lenth "acctcd" if more 10 charatcer need trim 10 character , if less need valuen is. value can come multiple times.please let me know issue in code input:
<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:body> <ns2:claimsrequest xmlns:ns2="http://example.com"> <externalidgroup> <acctcd>plan1 options</acctcd> </externalidgroup> <externalidgroup> <acctcd>plan2 options</acctcd> </externalidgroup> </ns2:claimsrequest> </soap:body> </soap:envelope>
xsl code:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:dp="http://www.datapower.com/extensions" xmlns:xsl="http://www.w3.org/1999/xsl/transform" extension-element-prefixes="dp" exclude-result-prefixes="dp" version="1.0"> <xsl:template match="/"> <claimsrequest> <xsl:for-each select="//externalidgroup"> <xsl:variable name="accode"> <xsl:value-of select="acctcd"/> </xsl:variable> <xsl:variable name="accode1"> <xsl:choose> <xsl:when test="string-length($accode) > 10"> <xsl:value-of select="substring($accode, 1,10)"/> </xsl:when> <xsl:otherwise><xsl:value-of select="$accode"/></xsl:otherwise> </xsl:choose> </xsl:variable> <claimdetail> <accountcode><xsl:value-of select="acctcd1"/></accountcode> </claimdetail> </xsl:for-each> </claimsrequest> </xsl:template> </xsl:stylesheet> desired output : <claimsrequest> <claimdetail> <accountcode>plan1 opti</accountcode> </claimdetail> <claimdetail> <accountcode>plan2</accountcode> </claimdetail> </claimsrequest>
i don't understand how derived desired output input. suspect need :
<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:template match="/"> <claimsrequest> <xsl:for-each select="//externalidgroup"> <claimdetail> <accountcode> <xsl:value-of select="substring(acctcd, 1, 10)"/> </accountcode> </claimdetail> </xsl:for-each> </claimsrequest> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment