Re: How to code XSL to display two XML elements side by side?

Subject: Re: How to code XSL to display two XML elements side by side?
From: Nick Browne <NickBrowne@xxxxxxxxxxxxxxx>
Date: Tue, 27 Jun 2000 11:03:46 +0100
"Xu, Xiaocun" wrote:

> Hi,
>         I have SoldTo and ShipTo info in XML that I need to display
> side-by-side in HTML.  I was using <table> HTML element to do side-by-side


Try :

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="";>
 <xsl:template match="/">

  <!-- order element is a dummy element wrapped around your data. Assumes that
there is
          more than one set of addresses and  makes the xml
legal                                      -->

   <xsl:for-each select="order">

    <TABLE width="100%" border="0"><!-- add table header etc. -->

     <!-- pass pairs of the same address child elements text to the display
template -->

     <xsl:call-template name="showAddrLine">
      <xsl:with-param name="addrLine" select="soldto/lastname/text() |


     <!-- repeat the call-template for each soldto/shipto child element -->


      Here's the rest of the page info ...

     <!-- Add the Shipto address again, pass only shipto address child element
text to
            the display template this time       -->

    <TABLE width="100%" border="0">

     <xsl:call-template name="showAddrLine">
      <xsl:with-param name="addrLine" select="shipto/lastname/text()"/>

     <!-- repeat the above for each shipto child element -->



 <!-- simple template to just show a part of the address. Skip the second
      cell if the node set passed only contains one text node.          -->

 <xsl:template name="showAddrLine">
  <xsl:param name="addrLine"/>
    <TD><font size="2"><xsl:value-of select="$addrLine[1]"/></font></TD>

    <xsl:if test="count($addrLine) &gt; 1">
     <TD><font size="2"><xsl:value-of select="$addrLine[2]"/></font></TD>


No doubt there are ways of putting the complete shipto info complete with
formatting tags into a variable for re-use .... and a way of looping through
each child element to save repeating the call-template but I'll leave that to

Nick Browne
Slipstone Ltd

 XSL-List info and archive:

Current Thread