Multiple views on an xml document

Subject: Multiple views on an xml document
From: "Parker, Daniel" <Daniel.Parker@xxxxxxxxxx>
Date: Sun, 5 Nov 2000 10:16:42 -0800
Consider the following xml document:

<stocks>
   <stock>
      <symbol>IBM</symbol>
      <desc></desc>
   </stock>
</stocks>

Now consider the problem of generating two html views on it:  a summary 
view (showing only symbol) and a detailed view (showing both symbol and 
desc.) The decision about which view to generate is based on a parameter 
in the principle xsl stylesheet, something like

<xsl:import href="summary-view.xsl"/>
<xsl:import href="detailed-view.xsl"/>
    
<xsl:param name="show-details"/>

<xsl:template match="/">

<xsl:choose>
   <xsl:when test="$show-details='yes'">
       <!-- generate detailed view -->
   </xsl:when>
   <xsl:otherwise>
       <!-- generate summary view -->
   </xsl:otherwise>
</xsl:choose>   

</xsl:template>              

One approach would be to call named templates show-detailed-view or 
show-summary-view as the case may be, but that willn't work if the 
both implementations require templates that match on "stock".  As 
presented, templates that match on "stock" imported through 
"summary-view.xsl" will have precedence over the ones imported through 
"detailed-view.xsl".  

Another approach that does work is to define templates with "summary" and 
"detailed" modes.  It should also be possible to use predicates in the 
summary and detailed templates based on the "show-details" parameter.  But 
I'm convinced I must be missing something.  Does anyone have any insights 
into a nice elegent solution to this class of problems?

Regards,
Daniel Parker


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


Current Thread