Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 16th, 2013, 08:21 AM
Registered User
 
Join Date: Jul 2013
Posts: 6
Thanks: 1
Thanked 1 Time in 1 Post
Default XSLT setting fixed width in for-each-group fields

Code:
<?xml version="1.0" encoding="UTF-8"?>
        <passengergroup>
         <passengerList>
            <passDetails>
                <route>LONDON</route>
                <lastname>RAY</lastname>
    	  <firstname>DONALD</firstname>
    	<country>UK</country>
            </passDetails>
            <seatDetails>
                <SeatNo>1A</SeatNo>
            </seatDetails>
            <customervalue>good</customervalue>
         </passengerList>
         <passengerList>
            <passDetails>
                <route>LONDON</route>
                <lastname>RAY</lastname>
    			<firstname>DONALD</firstname>
    			<country>UK</country>
            </passDetails>
            <seatDetails>
                <SeatNo>1B</SeatNo>
            </seatDetails>
            <customervalue>good</customervalue>
        </passengerList>
        <passengerList>
            <passDetails>
                <route>DELHI</route>
                <lastname>RATHORE</lastname>
    			<firstname>ALAN</firstname>
    			<country>IND</country>
            </passDetails>
            <seatDetails>
                <SeatNo>2C</SeatNo>
            </seatDetails>
            <customervalue>okey</customervalue>
        </passengerList>
        <passengerList>
            <passDetails>
                <route>DELHI</route>
                <lastname>RATHORE</lastname>
    			<firstname>ALAN</firstname>
    			<country>IND</country>
            </passDetails>
            <seatDetails>
                <SeatNo>2D</SeatNo>
            </seatDetails>
            <customervalue>okey</customervalue>
        </passengerList>
    	</passengergroup>    
         XSLT CODE
    
         <?xml version="1.0" encoding="UTF-8"?>
         <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/
         Transform"  
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
        <xsl:output method="text" />
        <xsl:template name="fixWidth">
            <xsl:param name="width"/>
            <xsl:param name="data"/>
            <xsl:param name="dataLength">
                <xsl:value-of select="fn:min( ( fn:number($width), fn:string-length($data) ) )"/>
            </xsl:param>
            <xsl:param name="paddingLength">
                <xsl:value-of select="$width - $dataLength"/>
            </xsl:param>
            <xsl:call-template name="padding">
                <xsl:with-param name="count" select="$paddingLength"/>
            </xsl:call-template>
            <xsl:value-of select="fn:substring($data,1,fn:number($dataLength))"/>
        </xsl:template>
       
              <xsl:template name="padding">
            <xsl:param name="count"/>
            <xsl:if test="$count > 0">
                <xsl:text> </xsl:text>
                <xsl:call-template name="padding">
                    <xsl:with-param name="count" select="$count - 1"/>
                </xsl:call-template>
            </xsl:if>
        </xsl:template>
        <xsl:template match="/">
                <xsl:apply-templates select="passengergroup" />
        </xsl:template>
    	
        <xsl:template match="passengergroup">
    	    	<xsl:if test="passengerList/customervalue='good'">
            <xsl:for-each-group select="passengerList" 
          group-by="concat  (passDetails/route, ' ',passDetails/firstname,' ',passDetails/lastname)">
                <xsl:value-of select="current-grouping-key()" />
                <xsl:text> </xsl:text>
    		<!--	<xsl:call-template name="fixWidth">
                    <xsl:with-param name="width">4</xsl:with-param>
                    <xsl:with-param name="data">
                        <xsl:value-of select="current-group()/seatDetails/SeatNo" separator=" " />
                    </xsl:with-param>
                </xsl:call-template>-->
                <xsl:value-of select="current-group()/seatDetails/SeatNo" separator=" " />
                <xsl:value-of select="'
'" />
            </xsl:for-each-group>
    		</xsl:if>
    		
    		<xsl:if test="passengerList/customervalue!='good'">
    		
            <xsl:for-each-group select="passengerList"
            group-by="concat(passDetails/route, ' ',passDetails/firstname,' ',passDetails/country)">
                <xsl:value-of select="current-grouping-key()" />
                <xsl:text> </xsl:text>
                <xsl:value-of select="current-group()/seatDetails/SeatNo" separator=" " />
                <xsl:value-of select="'
'" />
            </xsl:for-each-group>
    		</xsl:if>  
          </xsl:template>
    
        </xsl:stylesheet>
Output

I fixed it.....its worked

Last edited by santhakumar; July 16th, 2013 at 12:43 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing Fixed Width .txt Document and Then Some! Diretemus Access VBA 8 March 26th, 2008 07:27 AM
Fixed Width text file to MSDE with C# mgudmund C# 2005 3 November 9th, 2007 05:09 AM
Import a fixed width txt file to access subhanak Access VBA 12 May 5th, 2006 05:35 AM
Automate import (fixed width) U.N.C.L.E. Access VBA 0 February 3rd, 2006 06:55 PM
DTS Fixed Width File Import rochak SQL Server DTS 3 September 26th, 2005 09:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.