Rahul,
This will do what you want:
B B <?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"
B B B B version="2.0">
B B B B <xsl:template match="/">
B B B B B B B B <xsl:result-document href="source-01-output.xml">
B B B B B B B B B B B B <xsl:apply-templates/>
B B B B B B B B </xsl:result-document>
B B B B </xsl:template>
B B B B <xsl:template match="country">
B B B B B B B B <xsl:copy>
B B B B B B B B B B B B <xsl:for-each-group select="*" group-by="city">
B B B B B B B B B B B B B B B B <xsl:element name="city">
B B B B B B B B B B B B B B B B B B B B <xsl:attribute name="type"
select="current-grouping-key()"/>
B B B B B B B B B B B B B B B B B B B B <xsl:copy-of
select="current-group()[1]/pin"/>
B B B B B B B B B B B B B B B B B B B B <xsl:for-each
select="current-group()">
B B B B B B B B B B B B B B B B B B B B B B B B <xsl:element name="zip">
B B B B B B B B B B B B B B B B B B B B B B B B B B B B <xsl:attribute
name="type" select="zip"/>
B B B B B B B B B B B B B B B B B B B B B B B B B B B B <xsl:element
name="phone">
B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B <xsl:attribute
name="type" select="phone"/>
B B B B B B B B B B B B B B B B B B B B B B B B B B B B </xsl:element>
B B B B B B B B B B B B B B B B B B B B B B B B </xsl:element>
B B B B B B B B B B B B B B B B B B B B </xsl:for-each>
B B B B B B B B B B B B B B B B </xsl:element>
B B B B B B B B B B B B </xsl:for-each-group>
B B B B B B B B </xsl:copy>
B B B B </xsl:template>
</xsl:stylesheet>B
Terry Badger
On Wednesday, June 12, 2019, 5:33:20 AM EDT, Rahul Singh
rahulsinghindia15@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
I need help for xsl.
Actually Grouping is not working in my xsl, Input and expected output are
given below.
Input xml:
<country>
B <states>
B B <city>Albama</city>
B B <pin>1</pin>
B B <zip>aa</zip>
B B <phone>12</phone>
B </states>
B <states>
B B <city>Albama</city>
B B <pin>1</pin>
B B <zip>ab</zip>
B B <phone>11</phone>
B </states>
B <states>
B B <city>Albama</city>
B B <pin>1</pin>
B B <zip>ic</zip>
B B <phone>14</phone>
B </states>
B <states>
B B <city>Austrialia</city>
B B <pin>9</pin>
B B <zip>ac</zip>
B B <phone>04</phone>
B </states>
B <states>
B B <city>Canada</city>
B B <pin>8</pin>
B B <zip>pc</zip>
B B <phone>54</phone>
B </states>
</country>
Expected Output XML:
<country>
B B <city type="Albama">
B B B <pin type="1">
B B B B <zip type="aa">
B B B B B <phone type="12"/>
B B B B </zip>
B B B B <zip type="ab">
B B B B B <phone type="11"/>
B B B B </zip>
B B B B <zip type="ac">
B B B B B <phone type="14"/>
B B B B </zip>
B B B </pin>
B B </city>
<city type="Austrialia">
B B B <pin type="9">
B B B B <zip type="ac">
B B B B B <phone type="04"/>
B B B B </zip>
B B B </pin>
B B </city>
<city type="Canada">
B B B <pin type="8">
B B B B <zip type="pc">
B B B B B <phone type="54"/>
B B B B </zip>
B B B </pin>
B B </city>
</country>
B B XSL-List info and archive
EasyUnsubscribe (by email)
|