Re: [xsl] Arbitrary XML document merge and styling with XSLT

Subject: Re: [xsl] Arbitrary XML document merge and styling with XSLT
From: "Mike Haarman" <mhaarman@xxxxxxxxxxxxxxxxxx>
Date: Wed, 16 Jul 2003 11:41:07 -0500
Scott,

You could use import precedence to manage this requirement.  Let your main XSL
file be a driver which imports the desired template behavior based on the value
of mode.

Mike

----- Original Message ----- 
From: "Scott Powell" <scotthpowell@xxxxxxxxx>
To: <XSL-List@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, July 16, 2003 10:23 AM
Subject: [xsl] Arbitrary XML document merge and styling with XSLT


> Thanks for all the advice on the site for merging
> multiple XML documents into one.
>
> In all of the samples I've seen, the merging XSLT file
> applies the same templates to all source nodes.  What
> if you want different styles applied to nodes with the
> same name from the two documents?
>
> Let's say page.xml lists all the xml files to merge
> (see below); the mode node indicates which template
> mode to use in the transformation file.  Page.xsl
> contains the transformation instructions, making the
> appropriate document() calls as needed.
>
> But I've discovered that apply-templates' mode=""
> value must be a constant.  All my efforts to use the
> mode value from page.xml have fallen over.
>
> Is there a way to do this sort of "generic" merge
> within a single xsl file without hard-coding the match
> logic or using xsl:if's?
>
> Can name spaces help me here some how?
>
> Of would I be better off handling this within an ASP
> script?  ASP could read page.xml and then call a
> series of transforms based on the <element> nodes?
>
> Thanks for your advice and help....
>
> Scott
>
> ======================================================
> page.xml (contains a list of xml files to merge along
> with a MODE element I'd like to use to dictate which
> templates should be applied in the page.xsl file)
> ======================================================
> <?xml version="1.0" encoding="UTF-8"?>
> <page>
>   <element>
>     <mode>main</mode>
>     <file>main_menu.xml</file>
>   </element>
>   <element>
>     <mode>left</mode>
>     <file>left_menu.xml</file>
>   </element>
> </page>
>
>
> ======================================================
> page.xsl (Attempts to load each file in page.xml and
> apply-templates.  But I'd like to differentiate which
> templates are used for nodes with the same name where
> I want different styling)
> ======================================================
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> <xsl:output method="html"/>
> <xsl:template match="page">
>   <xsl:for-each select="element">
>     <xsl:apply-templates select="document(file)"
> mode="**** I would like to use the MODE value in the
> file but all attempts to use a variable here are
> rejected ****"></xsl:apply-templates>
>   </xsl:for-each>
> </xsl:template>
>
>
> <xsl:template match="menu" mode="main">
> <!-- formatting code -->
> </xsl:template>
>
> <xsl:template match="menu" mode="left">
> <!-- formatting code -->
> </xsl:template>
>
>
>
> ======================================================
> left_menu.xml (contains a list of graphic refs for a
> navigation menu)
> ======================================================
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE menu SYSTEM "menu.dtd">
> <menu name="weddings">
>   <item name="weddings_menu_how" href="index.htm">
>     <icon>
>       <iconOn width="101"
> height="18">weddings_menu_how.gif</iconOn>
>       <iconOff width="101"
> height="18">weddings_menu_how_f2.gif</iconOff>
>       <alt>how &amp; why</alt>
>     </icon>
>   </item>
> </menu>
>
> =====================================================
> main_menu.xml (contains a simple list of links and
> labels for a top nav bar)
> =====================================================
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE menu SYSTEM "menu.dtd">
> <menu>
>   <item href="index.htm">
>     <label>home</label>
>   </item>
>   <item href="../tours/subpage.asp">
>     <label>travel &amp; tours</label>
>   </item>
> </menu>
>
>
>
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>


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


Current Thread