Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Displaying multiple templates

    Hi, I have a question that's been puzzling me for awhile.

    XML example:
    Code:
    <customers>
    	<customer>
    		<name>Dante Moses</name>
    		<address>1234 James St</address>
    	</customer>
    	<customer>
    		<name>Jay Bird</name>
    		<address>234 Abbots Dr</address>
    	</customer>
    	<customer>
    		<name>Jessica Dorre</name>
    		<address>333 Abe Road</address>
    	</customer>
    	<customer>
    		<name>Tad Pole</name>
    		<address>66 Commons</address>
    	</customer>
    	<customer>
    		<name>Angela Gamby</name>
    		<address>99 Balloons</address>
    	</customer>
    	<customer>
    		<name>Dilon Blue</name>
    		<address>88 Crank</address>
    	</customer>
    </customers>
    Desired HTML in 2 column table output:


    Bill Ship
    Dante Moses Dante Moses
    1234 James St 1234 James St


    Ship Ship
    Jessica Dorre Tad Pole
    333 Abe Road 66 Commons


    Ship Ship
    Angela Gamby Dilon Blue
    99 Balloons 88 Crank

    Current HTML output:

    Bill Ship Ship
    Dante Moses Dante Moses Jessica Dorre
    1234 James St 1234 James St 333 Abe Road


    Bill Ship Ship
    Tad Pole Angela Gamby Dilon Blue
    66 Commons 99 Balloons 88 Crank

    Bill should only occur once followed by all existing Ships. While it's showing all the Ships (as wanted), Bill is repeated in every row, turning a 2 column into 3.

    Current code:
    Code:
    <xsl:key name="group-by-address" match="customers" use="concat(address , ' ' )"/>
    
    <xsl:param name="column" select="2" />
    <xsl:template match="customers">
    <table>
    	<xsl:apply-templates select="customers[position() mod $column = 1]" mode="row" />
    </table>
    </xsl:template>
    
    <xsl:template match="customer" mode="row">
    <tr>
        <xsl:apply-templates select=".|following-sibling::customer[position() &lt; $column]" mode="cell" />
    </tr>
    </xsl:template>
    
    <xsl:template match="customer" mode="cell">
    <xsl:variable name="once" select="position()" />
    <xsl:for-each select="key('group-by-address', concat( address , ' ' ))">
    <xsl:if test="$once = 1">
    <td>
          
             	Bill<br />
                    <xsl:value-of select="name" /><br />
                    <xsl:value-of select="address" />
         
    </td>
    </xsl:if>
    </xsl:for-each>
    
    <td>
    	      Ship<br />
                 <xsl:value-of select="name" /><br />
                 <xsl:value-of select="address" />
    </td>
    </xsl:template>
    </xsl:stylesheet>
    Any ideas? Thank you.
    Last edited by Alex Vincent; 05-14-2013 at 11:13 PM. Reason: adding code tags

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,461
    Thanks
    1
    Thanked 23 Times in 21 Posts
    Is this a homework assignment?
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #3
    New to the CF scene
    Join Date
    May 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No, it is not. I'm fairly new to XML and I'm looking for help or resources. Thank you.

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,307
    Thanks
    23
    Thanked 612 Times in 611 Posts
    Your xml just has names and addresses. How are you going to if it's Bill To: ( yes am assuming cause you don't explain things) or Ship To:. And if both bill/ship are always the same what difference does it make to have two columns?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •