wrap XSLT result in a CDATA block - xslt

I doing an XSLT transformation.
input message:
<Accounts operation="query">
<Account operation="query">
<Home_spcPage>google.com</Home_spcPage>
<Id>1-NP8S</Id>
</Account>
</Accounts>
which should get transformed to :
<ipString>
<![CDATA[<Accounts operation="update" boNameVar="Account" bcNameVar="Account">
<Account operation="update">
<Home_spcPage>google.com</Home_spcPage>
<Id>1-NP8S</Id>
</Account>
</Accounts>]]>
</ipString>
I am trying with the below XSLT.
<xsl:stylesheet xmlns:crma="www.c123.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output indent="yes" method="xml"/>
<xsl:variable name="messageBlock">
<xsl:call-template name="main"/>
</xsl:variable>
<xsl:template match="/" name="main">
<xsl:apply-templates select="#*|node()"/>
</xsl:template>
<xsl:template match="#*|node()">
<xsl:variable name="level" select="count(ancestor::node())"/>
<xsl:copy>
<xsl:choose>
<xsl:when test="$level=2">
<xsl:attribute name="operation">
<xsl:value-of select="'update'"/>
</xsl:attribute>
<xsl:variable name="currNodeVar" select="name()"/>
<xsl:if test="$currNodeVar='Account'">
<xsl:attribute name="boNameVar">Account</xsl:attribute>
<xsl:attribute name="bcNameVar">Account</xsl:attribute>
</xsl:if>
<xsl:if test="$currNodeVar='Contact'">
<xsl:attribute name="boNameVar">Contact</xsl:attribute>
<xsl:attribute name="bcNameVar">Contact</xsl:attribute>
</xsl:if>
</xsl:when>
<xsl:when test="$level=4">
<xsl:attribute name="operation">
<xsl:value-of select="'update'"/>
</xsl:attribute>
<xsl:variable name="currBCNameVar" select="name()"/>
<xsl:variable name="parBCNameVar" select="name(../..)"/>
</xsl:when>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:copy-of select="$messageBlock"/>
</xsl:template>
<xsl:template match="/">
<xsl:element name="ipString">
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
<xsl:copy-of select="$messageBlock"/>
<xsl:text disable-output-escaping="yes">]]></xsl:text>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
but not getting the desired results . It seems like the XSLT is not considering the entire XML.
Any help is appreciated .
Thanks,
Naveen

Related

Combine space-separated attributes in XSLT

The transform I'm working on mergers two templates that has attributes that are space-separated.
An example would be:
<document template_id="1">
<header class="class1 class2" />
</document>
<document template_id="2">
<header class="class3 class4" />
</document>
And after the transform I want it to be like this:
<document>
<header class="class1 class2 class3 class4" />
</document>
How to achieve this?
I have tried (writing from memory):
<xsl:template match="/">
<header>
<xsl:attribute name="class">
<xsl:for-each select=".//header">
<xsl:value-of select="#class"/>
</xsl:for-each>
</xsl:attribute>
</header>
</xsl:template>
But that appends them all together, but I need them separated... and would be awesome if uniqued as well.
Thank you
Try this template, which simply adds a space before all the headers, apart from the first
<xsl:template match="/">
<header>
<xsl:attribute name="class">
<xsl:for-each select=".//header">
<xsl:if test="position() > 1">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:value-of select="#class"/>
</xsl:for-each>
</xsl:attribute>
</header>
</xsl:template>
If you want your classes without repetitions, then use the following XSLT:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<document>
<xsl:variable name="cls1">
<xsl:for-each select=".//header/#class">
<xsl:call-template name="tokenize">
<xsl:with-param name="txt" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="cls" select="exsl:node-set($cls1)"/>
<header>
<xsl:attribute name="class">
<xsl:for-each select="$cls/*[not(preceding-sibling::* = .)]">
<xsl:value-of select="."/>
<xsl:if test="position() < last()">
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:attribute>
</header>
</document>
</xsl:template>
<xsl:template name="tokenize">
<xsl:param name="txt"/>
<xsl:if test="$txt">
<xsl:if test="contains($txt, ' ')">
<cls>
<xsl:value-of select="substring-before($txt, ' ')"/>
</cls>
<xsl:call-template name="tokenize">
<xsl:with-param name="txt" select="substring-after($txt, ' ')"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="not(contains($txt, ' '))">
<cls>
<xsl:value-of select="$txt"/>
</cls>
</xsl:if>
</xsl:if>
</xsl:template>
</xsl:transform>
In XSLT 1.0 it is much more difficult than in XSLT 2.0, but as you see,
it is possible.
Edit
A revised version using Muenchian grouping (inspired by comment from Michael):
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:variable name="cls1">
<xsl:for-each select=".//header/#class">
<xsl:call-template name="tokenize">
<xsl:with-param name="txt" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="cls2" select="exsl:node-set($cls1)"/>
<xsl:key name="classKey" match="cls" use="."/>
<xsl:template match="/">
<document>
<header>
<xsl:attribute name="class">
<xsl:for-each select="$cls2/*[generate-id() = generate-id(key('classKey', .)[1])]">
<xsl:value-of select="."/>
<xsl:if test="position() < last()">
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:attribute>
</header>
</document>
</xsl:template>
<xsl:template name="tokenize">
<xsl:param name="txt"/>
<xsl:if test="$txt">
<xsl:if test="contains($txt, ' ')">
<cls>
<xsl:value-of select="substring-before($txt, ' ')"/>
</cls>
<xsl:call-template name="tokenize">
<xsl:with-param name="txt" select="substring-after($txt, ' ')"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="not(contains($txt, ' '))">
<cls>
<xsl:value-of select="$txt"/>
</cls>
</xsl:if>
</xsl:if>
</xsl:template>
</xsl:transform>

ce:chem tag to be converted to mml:math

Is there a way to convert these elsevier tags into mml:math tags?
<ce:chem>PEG<ce:inf>BOUND</ce:inf>
<ce:hsp sp="0.25"/>=<ce:hsp sp="0.25"/>PEG<ce:inf>TOT</ce:inf>
<ce:hsp sp="0.25"/>-<ce:hsp sp="0.25"/>PEG<ce:inf>FINAL</ce:inf>
</ce:chem>
Try this:
XML: (Ensure ce:chem content should not have line breaks and comment text. grouping functions can do better than my code, but I placed this jsut to meet the requirement)
<article xmlns:ce="http://www.elsevier.com/xml/common/dtd"
xmlns:sb="http://www.elsevier.com/xml/common/struct-bib/dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:mml="http://www.w3.org/1998/Math/MathML">
<p>
<ce:chem>PEG<ce:inf>BOUND</ce:inf><ce:hsp sp="0.25"/>=<ce:hsp sp="0.25"/>PEG<ce:inf>TOT</ce:inf><ce:hsp sp="0.25"/>-<ce:hsp sp="0.25"/>PEG<ce:inf>FINAL</ce:inf>A<ce:sup>2</ce:sup></ce:chem>
</p>
</article>
XSLT 2.0: (latest xslt)
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ce="http://www.elsevier.com/xml/common/dtd"
xmlns:sb="http://www.elsevier.com/xml/common/struct-bib/dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:ja="http://www.elsevier.com/xml/ja/dtd">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="#*|node()"><xsl:copy><xsl:apply-templates/></xsl:copy></xsl:template>
<xsl:template match="ce:chem">
<xsl:copy>
<xsl:apply-templates select="node()[not(self::ce:inf)][not(self::ce:sup)] | #*" />
</xsl:copy>
</xsl:template>
<xsl:key name="ksub" match="ce:inf" use="generate-id(preceding-sibling::node()[1][self::text()])"/>
<xsl:key name="ksup" match="ce:sup" use="generate-id(preceding-sibling::node()[1][self::text()])"/>
<xsl:template match="ce:chem/text()">
<xsl:choose>
<xsl:when test="following-sibling::node()[1][name()='ce:inf']">
<xsl:element name="ce:msub">
<xsl:call-template name="tempNameElements"/>
<xsl:apply-templates select="key('ksub', generate-id())" />
</xsl:element>
</xsl:when>
<xsl:when test="following-sibling::node()[1][name()='ce:sup']">
<xsl:element name="ce:msup">
<xsl:call-template name="tempNameElements"/>
<xsl:apply-templates select="key('ksup', generate-id())" />
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="tempNameElements"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="ce:hsp">
<xsl:element name="mml:mspace">
<xsl:attribute name="width"><xsl:value-of select="#sp"/></xsl:attribute>
</xsl:element>
</xsl:template>
<xsl:template match="ce:inf">
<xsl:for-each select="node()">
<xsl:call-template name="tempNameElements"/>
</xsl:for-each>
</xsl:template>
<xsl:template match="ce:sup">
<xsl:for-each select="node()">
<xsl:call-template name="tempNameElements"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="tempNameElements">
<xsl:choose>
<xsl:when test="starts-with(replace(self::text(), '([A-z]+)', 'A'), 'A')">
<xsl:element name="mml:mi"><xsl:value-of select="."/></xsl:element>
</xsl:when>
<xsl:when test="starts-with(replace(self::text(), '([0-9]+)', '9'), '9')">
<xsl:element name="mml:mn"><xsl:value-of select="."/></xsl:element>
</xsl:when>
<xsl:when test="matches(self::text(), '^(\(|\[|\{|=|\-)$')">
<xsl:element name="mml:mo"><xsl:value-of select="."/></xsl:element>
</xsl:when>
<xsl:otherwise><xsl:element name="mml:mtext"><xsl:value-of select="."/></xsl:element></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Result:
<?xml version="1.0" encoding="UTF-8"?>
<article xmlns:ce="http://www.elsevier.com/xml/common/dtd"
xmlns:sb="http://www.elsevier.com/xml/common/struct-bib/dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:mml="http://www.w3.org/1998/Math/MathML">
<p>
<ce:chem>
<ce:msub>
<mml:mi>PEG</mml:mi>
<mml:mi>BOUND</mml:mi>
</ce:msub>
<mml:mspace width="0.25"/>
<mml:mo>=</mml:mo>
<mml:mspace width="0.25"/>
<ce:msub>
<mml:mi>PEG</mml:mi>
<mml:mi>TOT</mml:mi>
</ce:msub>
<mml:mspace width="0.25"/>
<mml:mo>-</mml:mo>
<mml:mspace width="0.25"/>
<ce:msub>
<mml:mi>PEG</mml:mi>
<mml:mi>FINAL</mml:mi>
</ce:msub>
<ce:msup>
<mml:mi>A</mml:mi>
<mml:mn>2</mml:mn>
</ce:msup>
</ce:chem>
</p>
</article>

Need to perform two transformation for the same content in xsl

I have two different transformation.After first transformation get over second need to be applied but not able to do.I have referred other stackoverflow post but its not working for me.
Sample Input:
<Para>1<AAA>2<BBB>3</BBB>4</AAA>5</Para>
Requirement is like BBB may available outside of AAA as well.We need to remove all AAA and put the value in comma separated format.
Expected output after First:
<Para>12<BBB>3</BBB>45</Para>
Expected output on the Second:
<Para>12,3,45</Para>
First:
Here i am just removing tag AAA from the content.And retriving its content and child.
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match ="*/AAA">
<xsl:apply-templates/>
</xsl:template>
Second:
Here I am just appending comma between the node element by removing all the tags inside para and retrieving its content.
<xsl:param name="Para"></xsl:param>
<xsl:template match="Para">
<xsl:copy>
<xsl:variable name="BBB-element-exists">
<xsl:for-each select="node()[self::BBB ][normalize-space(.)!='']">
<xsl:if test="(self::Change and (child::BBB)) or (self::BBB)">
<xsl:value-of select="'BBBexists'"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:if test="$BBB-element-exists = 'BBBexists'">
<xsl:for-each select=".//text()">
<xsl:if test="position() >1 and not(parent::Change) ">
<xsl:value-of select="','" />
</xsl:if>
<xsl:value-of select="normalize-space()" />
</xsl:for-each>
</xsl:if>
<xsl:if test="$BBB-element-exists != 'BBBexists'">
<xsl:for-each select=".//text()">
<xsl:value-of select="normalize-space()" />
</xsl:for-each>
</xsl:if>
</xsl:copy>
</xsl:template>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
You will need to use at least one mode to separate processing of the second step from the first:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="#*|node()" mode="#all">
<xsl:copy>
<xsl:apply-templates select="#*|node()" mode="#current"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*/AAA">
<xsl:apply-templates/>
</xsl:template>
<xsl:variable name="first-pass">
<xsl:apply-templates select="node()"/>
</xsl:variable>
<xsl:template match="/">
<xsl:apply-templates select="$first-pass/node()" mode="step2"/>
</xsl:template>
<xsl:template match="Para" mode="step2">
<xsl:copy>
<xsl:variable name="BBB-element-exists">
<xsl:for-each select="node()[self::BBB ][normalize-space(.)!='']">
<xsl:if test="(self::Change and (child::BBB)) or (self::BBB)">
<xsl:value-of select="'BBBexists'"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:if test="$BBB-element-exists = 'BBBexists'">
<xsl:for-each select=".//text()">
<xsl:if test="position() >1 and not(parent::Change) ">
<xsl:value-of select="','" />
</xsl:if>
<xsl:value-of select="normalize-space()" />
</xsl:for-each>
</xsl:if>
<xsl:if test="$BBB-element-exists != 'BBBexists'">
<xsl:for-each select=".//text()">
<xsl:value-of select="normalize-space()" />
</xsl:for-each>
</xsl:if>
</xsl:copy>
</xsl:template>
</xsl:transform>

xml attribute replacement with xslt

How can i replace an attribute in xml using xsl transformation, depending on its value.
For example, if there is such xml
<Text Style='style1'>
...
</Text>
transform it to
<Text Font='Arial' Bold='true' Color='Red'>
...
</Text>
For Style='style2' set another attributes and values, for example Font='Sans' Italic='true'.
One posible way: ussing attribute sets. This stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:attribute-set name="style1">
<xsl:attribute name="Font">Arial</xsl:attribute>
<xsl:attribute name="Bold">true</xsl:attribute>
<xsl:attribute name="Color">Red</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="style2">
<xsl:attribute name="Font">Sans</xsl:attribute>
<xsl:attribute name="Italic">true</xsl:attribute>
</xsl:attribute-set>
<xsl:template match="Text[#Style='style1']">
<xsl:copy use-attribute-sets="style1">
<xsl:copy-of select="#*[name()!='Style']"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="Text[#Style='style2']">
<xsl:copy use-attribute-sets="style2">
<xsl:copy-of select="#*[name()!='Style']"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
With this input:
<root>
<Text Style='style1'></Text>
<Text Style='style2'></Text>
</root>
Output:
<Text Font="Arial" Bold="true" Color="Red"></Text>
<Text Font="Sans" Italic="true"></Text>
Other way: inline "attribute sets". This stylesheet:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="my"
exclude-result-prefixes="my">
<xsl:output indent="yes"/>
<my:style1 Font="Arial" Bold="true" Color="Red"/>
<my:style2 Font="Sans" Italic="true"/>
<xsl:template match="Text[#Style]">
<xsl:copy>
<xsl:copy-of select="document('')/*/my:*
[local-name()=current()/#Style]/#*"/>
<xsl:copy-of select="#*[name()!='Style']"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
You will need to have some kind of rule that you use to convert the style from one to the other. Making the assumption you are inputting html you will need something like.
<xsl:template match="#* | node()">
<xsl:choose>
<xsl:when test="local-name() = 'Style'">
<xsl:apply-templates select="." mode="Style" />
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="#Style" mode="Style">
<xsl:choose>
<xsl:when test="node() = 'style1'">
<xsl:attribute name="Font">Arial</xsl:attribute>
<xsl:attribute name="Bold">true</xsl:attribute>
<xsl:attribute name="Color">Red</xsl:attribute>
</xsl:when>
<xsl:when test="node() = 'style2'">
<xsl:attribute name="Font">Sans</xsl:attribute>
<xsl:attribute name="Bold">true</xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:template>

Grouping on Multiple Field

I am generating XML file from Database as below...
<?xml version = '1.0'?>
<T0019>
<IFTA_ACCOUNT>
<IFTA_CARRIER_ID_NUMBER>705</IFTA_CARRIER_ID_NUMBER>
<IFTA_LICENSE_NUMBER>631227666</IFTA_LICENSE_NUMBER>
<IFTA_BASE_COUNTRY>US</IFTA_BASE_COUNTRY>
<IFTA_BASE_STATE>AL</IFTA_BASE_STATE>
<IFTA_STATUS_CODE>0 </IFTA_STATUS_CODE>
<IFTA_STATUS_DATE>2009-01-01</IFTA_STATUS_DATE>
<IFTA_ISSUE_DATE>2009-01-01</IFTA_ISSUE_DATE>
<IFTA_EXPIRE_DATE>2009-12-01</IFTA_EXPIRE_DATE>
<IFTA_UPDATE_DATE>2008-12-30</IFTA_UPDATE_DATE>
<NAME_TYPE>LG</NAME_TYPE>
<NAME>K D L TRUCKING INC</NAME>
<ADDRESS_TYPE>PH</ADDRESS_TYPE>
<STREET_LINE_1>200 MARTIN LANE</STREET_LINE_1>
<CITY>OHATCHEE</CITY>
<STATE>AL</STATE>
<ZIP_CODE>36271</ZIP_CODE>
<COUNTY>CALHOUN COUNTY</COUNTY>
<COUNTRY>US</COUNTRY>
</IFTA_ACCOUNT>
<IFTA_ACCOUNT>
<IFTA_CARRIER_ID_NUMBER>705</IFTA_CARRIER_ID_NUMBER>
<IFTA_LICENSE_NUMBER>631227666</IFTA_LICENSE_NUMBER>
<IFTA_BASE_COUNTRY>US</IFTA_BASE_COUNTRY>
<IFTA_BASE_STATE>AL</IFTA_BASE_STATE>
<IFTA_STATUS_CODE>0 </IFTA_STATUS_CODE>
<IFTA_STATUS_DATE>2009-01-01</IFTA_STATUS_DATE>
<IFTA_ISSUE_DATE>2009-01-01</IFTA_ISSUE_DATE>
<IFTA_EXPIRE_DATE>2009-12-01</IFTA_EXPIRE_DATE>
<IFTA_UPDATE_DATE>2008-12-30</IFTA_UPDATE_DATE>
<NAME_TYPE>LG</NAME_TYPE>
<NAME>K D L TRUCKING INC</NAME>
<ADDRESS_TYPE>MA</ADDRESS_TYPE>
<STREET_LINE_1>200 MARTIN LANE</STREET_LINE_1>
<CITY>OHATCHEE</CITY>
<STATE>AL</STATE>
<ZIP_CODE>36271</ZIP_CODE>
<COUNTRY>US</COUNTRY>
</IFTA_ACCOUNT>
</T0019>
I have taken first two records from generated XSLT.
With the use of XSLT I have tried lot to group record on basis of
IFTA_LICENSE_NUMBER,IFTA_BASE_COUNTRY,IFTA_BASE_ST ATE,NAME_TYPE,ADDRESS_TYPE but i failed to generated XML like this..
<?xml version="1.0" encoding="UTF-8" ?>
<T0019>
<IFTA_ACCOUNT>
<IFTA_CARRIER_ID_NUMBER>705</IFTA_CARRIER_ID_NUMBER>
<IFTA_BASE_COUNTRY>US</IFTA_BASE_COUNTRY>
<IFTA_BASE_STATE>AL</IFTA_BASE_STATE>
<IFTA_LICENSE_NUMBER>631227666</IFTA_LICENSE_NUMBER>
<IFTA_STATUS_CODE>0</IFTA_STATUS_CODE>
<IFTA_STATUS_DATE>2009-01-01</IFTA_STATUS_DATE>
<IFTA_ISSUE_DATE>2009-01-01</IFTA_ISSUE_DATE>
<IFTA_EXPIRE_DATE>2009-12-01</IFTA_EXPIRE_DATE>
<IFTA_UPDATE_DATE>2008-12-30</IFTA_UPDATE_DATE>
<IFTA_NAME>
<NAME_TYPE>LG</NAME_TYPE>
<NAME>K D L TRUCKING INC</NAME>
<IFTA_ADDRESS>
<ADDRESS_TYPE>PH</ADDRESS_TYPE>
<STREET_LINE_1>200 MARTIN LANE</STREET_LINE_1>
<STREET_LINE_2 />
<CITY>OHATCHEE</CITY>
<STATE>AL</STATE>
<ZIP_CODE>36271</ZIP_CODE>
<COUNTY>CALHOUN COUNTY</COUNTY>
<COUNTRY>US</COUNTRY>
</IFTA_ADDRESS>
<IFTA_ADDRESS>
<ADDRESS_TYPE>MA</ADDRESS_TYPE>
<STREET_LINE_1>200 MARTIN LANE</STREET_LINE_1>
<STREET_LINE_2 />
<CITY>OHATCHEE</CITY>
<STATE>AL</STATE>
<ZIP_CODE>36271</ZIP_CODE>
<COUNTY />
<COUNTRY>US</COUNTRY>
</IFTA_ADDRESS>
</IFTA_NAME>
</IFTA_ACCOUNT>
</T0019>
Your example input records have two different ADDRESS_TYPE values, so if you were grouping by ADDRESS_TYPE, these two would be distinct. And since your output also shows the two distinct values, I assume that you don't really want ADDRESS_TYPE in your list of grouping keys. Is that the real problem?
The XSLT spec gives two strategies for composite keys. When I tried the 'concat' strategy with your data, and with your list of keys minus ADDRESS_TYPE, it grouped these two records together.
Thanks , I have applied following XSLT to solve this Problem.
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="T0019">
<xsl:copy>
<xsl:for-each-group select="IFTA_ACCOUNT" group-by="IFTA_LICENSE_NUMBER">
<xsl:for-each-group select="current-group()" group-by="IFTA_BASE_COUNTRY">
<xsl:for-each-group select="current-group()" group-by="IFTA_BASE_STATE">
<IFTA_ACCOUNT>
<xsl:apply-templates select="IFTA_CARRIER_ID_NUMBER|IFTA_BASE_COUNTRY|IFTA_BASE_STATE|IFTA_LICENSE_NUMBER|IFTA_STATUS_CODE|IFTA_STATUS_DATE|IFTA_ISSUE_DATE|IFTA_EXPIRE_DATE|IFTA_UPDATE_DATE"/>
<xsl:for-each-group select="current-group()" group-by="NAME_TYPE">
<IFTA_NAME>
<xsl:apply-templates select="NAME_TYPE|NAME"/>
<xsl:for-each select="current-group()">
<IFTA_ADDRESS>
<xsl:apply-templates select="ADDRESS_TYPE|STREET_LINE_1|STREET_LINE_2|CITY|STATE|ZIP_CODE|COUNTY|COUNTRY"/>
</IFTA_ADDRESS>
</xsl:for-each>
</IFTA_NAME>
</xsl:for-each-group>
</IFTA_ACCOUNT>
</xsl:for-each-group>
</xsl:for-each-group>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
<xsl:template match="IFTA_CARRIER_ID_NUMBER">
<IFTA_CARRIER_ID_NUMBER>
<xsl:value-of select="."/>
</IFTA_CARRIER_ID_NUMBER>
</xsl:template>
<xsl:template match="IFTA_LICENSE_NUMBER">
<IFTA_LICENSE_NUMBER>
<xsl:value-of select="."/>
</IFTA_LICENSE_NUMBER>
</xsl:template>
<xsl:template match="IFTA_BASE_COUNTRY">
<IFTA_BASE_COUNTRY>
<xsl:value-of select="."/>
</IFTA_BASE_COUNTRY>
</xsl:template>
<xsl:template match="IFTA_BASE_STATE">
<IFTA_BASE_STATE>
<xsl:value-of select="."/>
</IFTA_BASE_STATE>
</xsl:template>
<xsl:template match="IFTA_STATUS_CODE">
<IFTA_STATUS_CODE>
<xsl:value-of select="."/>
</IFTA_STATUS_CODE>
</xsl:template>
<xsl:template match="IFTA_STATUS_DATE">
<IFTA_STATUS_DATE>
<xsl:value-of select="."/>
</IFTA_STATUS_DATE>
</xsl:template>
<xsl:template match="IFTA_ISSUE_DATE">
<IFTA_ISSUE_DATE>
<xsl:value-of select="."/>
</IFTA_ISSUE_DATE>
</xsl:template>
<xsl:template match="IFTA_EXPIRE_DATE">
<IFTA_STATUS_DATE>
<xsl:value-of select="."/>
</IFTA_STATUS_DATE>
</xsl:template>
<xsl:template match="IFTA_UPDATE_DATE">
<IFTA_ISSUE_DATE>
<xsl:value-of select="."/>
</IFTA_ISSUE_DATE>
</xsl:template>
<xsl:template match="NAME_TYPE">
<NAME_TYPE>
<xsl:value-of select="."/>
</NAME_TYPE>
</xsl:template>
<xsl:template match="NAME">
<NAME_TYPE>
<xsl:value-of select="."/>
</NAME_TYPE>
</xsl:template>
<xsl:template match="ADDRESS_TYPE">
<ADDRESS_TYPE>
<xsl:value-of select="."/>
</ADDRESS_TYPE>
</xsl:template>
<xsl:template match="STREET_LINE_1">
<STREET_LINE_1>
<xsl:value-of select="."/>
</STREET_LINE_1>
</xsl:template>
<xsl:template match="STREET_LINE_2">
<STREET_LINE_2>
<xsl:value-of select="."/>
</STREET_LINE_2>
</xsl:template>
<xsl:template match="CITY">
<CITY>
<xsl:value-of select="."/>
</CITY>
</xsl:template>
<xsl:template match="STATE">
<STATE>
<xsl:value-of select="."/>
</STATE>
</xsl:template>
<xsl:template match="ZIP_CODE">
<ZIP_CODE>
<xsl:value-of select="."/>
</ZIP_CODE>
</xsl:template>
<xsl:template match="COUNTY">
<COUNTY>
<xsl:value-of select="."/>
</COUNTY>
</xsl:template>
<xsl:template match="COUNTRY">
<COUNTRY>
<xsl:value-of select="."/>
</COUNTRY>
</xsl:template>
</xsl:stylesheet>
Thanks to all for your wonderful help.