[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

grouping and subgroup problem

Subject: grouping and subgroup problem
From: ahamed meeran <akmeeran@xxxxxxxxx>
Date: Wed, 22 Sep 2010 18:15:13 +0400
 grouping and subgroup problem
<dataroot>
    <BU>
        <Classification1>Air Cargo</Classification1>
        <Customer>Freight International LLC</Customer>
        <City>parco</City>
        <Box>11745</Box>
        <TelCode>04</TelCode>
        <TelNo>3430060</TelNo>
        <FaxNo>3430075</FaxNo>
        <priority1>#</priority1>
        <Image>aaa.ai</Image>
    </BU>
    <BU>
        <Classification1>Air Cargo</Classification1>
        <Customer>Freight International LLC</Customer>
        <City>tazese</City>
        <Box>11745</Box>
        <TelCode>09</TelCode>
        <TelNo>3431234</TelNo>
        <FaxNo>3434321</FaxNo>
        <priority1>#</priority1>
        <Image>aaa.ai</Image>
    </BU>
    <BU>
        <Classification1>Air Cargo</Classification1>
        <Customer>Freight International LLC</Customer>
        <City>raseus</City>
        <Box>56899</Box>
        <TelCode>08</TelCode>
        <TelNo>347890</TelNo>
        <FaxNo>345678</FaxNo>
        <priority1>#</priority1>
        <Image>aassa.ai</Image>
    </BU>
    <BU>
        <Classification1>Air Cargo</Classification1>
        <Customer>ooohs International LLC</Customer>
        <City>uiiri</City>
        <Box>53499</Box>
        <TelCode>06</TelCode>
        <TelNo>347990</TelNo>
        <FaxNo>340988</FaxNo>
        <priority2>%</priority2>
        <Image>aaa.ai</Image>
    </BU>
    <BU>
        <Classification1>Air Cargo</Classification1>
        <Customer>kas International LLC</Customer>
        <City>kiriri</City>
        <Box>533699</Box>
        <TelCode>06</TelCode>
        <TelNo>347890</TelNo>
        <FaxNo>342588</FaxNo>
        <priority3>^</priority3>
        <Image>aaa.ai</Image>
    </BU>
    <BU>
        <Classification1>Air Cargo</Classification1>
        <Customer>kas International LLC</Customer>
        <City>kiriri</City>
        <Box>533699</Box>
        <TelCode>06</TelCode>
        <TelNo>347890</TelNo>
        <FaxNo>342588</FaxNo>
        <priority3>^</priority3>
        <Image>aaa.ai</Image>
    </BU>
</dataroot>
Hello All,

My XSLT look like this......



    <xsl:template match="/">
        <xsl:variable name="blocks" select="dataroot/BU"/>
        <xsl:variable name="images" select="dataroot/BU/Image"/>
        <xsl:variable name="customers" select="dataroot/BU/Customer"/>

        <Root>
            <xsl:result-document method="xml" href="alpha_out1.xml">
               <xsl:for-each-group select="dataroot/BU"
group-by="substring(Customer,1,1)">
                    <xsl:sort select="current-grouping-key()"
order="ascending"/>

                    <xsl:variable name="currentGroup"><xsl:value-of
select="current-grouping-key()"/></xsl:variable>
                    <xsl:for-each select=".">
                        <xsl:element name="title">
                            <xsl:value-of select="current-grouping-key()"/>

                        </xsl:element><xsl:text>&#xA;</xsl:text>
                         <xsl:for-each select="current-group()">
                            <!-- new sorting --> <xsl:sort
select="Customer" order="ascending"/>

                            <xsl:apply-templates/>
                        </xsl:for-each>
                       </xsl:for-each>
                </xsl:for-each-group>
                </xsl:result-document>
        </Root>
    </xsl:template>

    <xsl:template match="Customer">

        <xsl:if test="following-sibling::Image"><xsl:apply-templates
select="following-sibling::Image" mode="siblingImage"/></xsl:if>
        <Customer>
            <xsl:value-of select="."/>
            <xsl:text></xsl:text>
        </Customer>

        <xsl:text>&#xA;</xsl:text>
        <xsl:if test="following-sibling::Box | following-sibling::City
| following-sibling::TelCode | following-sibling::TelNo">
            <Address>
                <xsl:if test="string-length(following-sibling::Box)
&gt; 1">Box <xsl:value-of select="following-sibling::Box"/>
                    <xsl:text>, </xsl:text></xsl:if>
                <xsl:if test="string-length(following-sibling::City)
&gt; 1"><xsl:value-of select="following-sibling::City"/>
                    <xsl:text>, </xsl:text></xsl:if>

                <xsl:if test="string-length(following-sibling::TelNo)
&gt; 1"><xsl:text>&#9;</xsl:text>
                    <xsl:if
test="string-length(following-sibling::TelCode) &gt; 1">
                        <xsl:value-of
select="following-sibling::TelCode"/><xsl:text> </xsl:text></xsl:if>
                    <xsl:value-of select="following-sibling::TelNo"/></xsl:if>
            </Address>
            <xsl:text></xsl:text>
        </xsl:if>

        <xsl:text>&#xA;</xsl:text>

    </xsl:template>


    <!-- make an href value for Image element -->
    <xsl:template match="Image" mode="siblingImage">
        <!-- make the href value into a variable value -->
        <xsl:variable name="image">
            <xsl:value-of select="@href"/>
        </xsl:variable>
        <!-- get the image name <Image href="images\blue logo.eps"/> -->
        <xsl:variable name="imageFolder">
            <xsl:value-of select="substring-before($image,'\')"/>
        </xsl:variable>
        <xsl:variable name="imageHref">
            <xsl:value-of select="substring-after($image,'\')"/>
        </xsl:variable>
        <xsl:element name="Image">
            <xsl:choose>
                <xsl:when test="$platform='win'">
                    <!-- change any space to %20 -->
                    <xsl:variable name="winImage">
                        <xsl:value-of select="translate($imageHref,' ','%20')"/>
                    </xsl:variable>
                    <!-- build the Windows file path -->
                    <xsl:variable name="winPath">

<xsl:text>file:///D:/new%20dicrectory/Alpha%20New/images/</xsl:text>
                        <xsl:value-of select="."/>

                    </xsl:variable>
                    <!-- put the windows path to the image into the
href attribute value -->
                    <xsl:attribute name="href">
                        <xsl:value-of select="$winPath"/>
                    </xsl:attribute>
                </xsl:when>
                <xsl:when test="$platform='mac'">
                    <xsl:attribute name="href">
                        <!-- not sure how to handle the mac path so
will just copy it for now -->
                        <xsl:value-of select="$image"/>
                    </xsl:attribute>
                </xsl:when>
            </xsl:choose>

        </xsl:element>
        <xsl:text>&#xA;</xsl:text>
    </xsl:template>

    <xsl:template match="*|@*"/>
</xsl:stylesheet>


My Result look like this.............


<title>F</title>
<Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
<Customer>Freight International LLC</Customer>
<Address>Box 11745, parco,     04 3430060</Address>
<Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
<Customer>Freight International LLC</Customer>
<Address>Box 11745, tazese,     09 3431234</Address>
<Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aassa.ai"/>
<Customer>Freight International LLC</Customer>
<Address>Box 56899, raseus,     08 347890</Address>
<title>k</title>
<Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
<Customer>kas International LLC</Customer>
<Address>Box 533699, kiriri,     06 347890</Address>
<Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
<Customer>kas International LLC</Customer>
<Address>Box 533699, kiriri,     06 347890</Address>
<title>o</title>
<Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
<Customer>ooohs International LLC</Customer>
<Address>Box 53499, uiiri,     06 347990</Address>

I want final result look like this....


<Root>
<title>F</title>
<Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
<Customer>Freight International LLC</Customer>
<Address>Box 11745, parco,     04 3430060</Address>
<Address>Box 11745, tazese,     09 3431234</Address>
<Address>Box 56899, raseus,     08 347890</Address>
<title>k</title>
<Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
<Customer>kas International LLC</Customer>
<Address>Box 533699, kiriri,     06 347890</Address>
<title>o</title>
<Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
<Customer>ooohs International LLC</Customer>
<Address>Box 53499, uiiri,     06 347990</Address>
</Root>

One Customer having few branches so braches should come under the
customer, Same time i want remove duplicate XML data(Maybe same data
come repeat)

Regards
Ahmed

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.