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

etc.

Try :

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 <xsl:template match="/">
  <HTML><BODY>

  <!-- 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() |

shipto/lastname/text()"/>
     </xsl:call-template>

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

    </TABLE>

      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()"/>
     </xsl:call-template>

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

    </TABLE>

   </xsl:for-each>
  </BODY></HTML>
 </xsl:template>

 <!-- 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"/>
   <TR>
    <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>
    </xsl:if>
   </TR>
 </xsl:template>

</xsl:stylesheet>

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
you.

Nick Browne
Slipstone Ltd




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread