xsl-list
[Top] [All Lists]

RE: [xsl] fallback to a default template in xsl processing

2008-04-25 05:40:14
Hi,

maybe my practice of always matching the root influences the double 
matching(?). The stylesheet below has been reduced to the main '/' match and 
then just the 'headers to the templates that process the different matched nodes



<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <xsl:output method="html"/>
        <xsl:template match="/">

                <html>
                        <head>
                                <title>
                                        <xsl:value-of select="name(LIMS)"/>
                                </title>
                        </head>
                        <body>
                                <xsl:choose>
                                        <xsl:when 
test="name(LIMS/*)='SUBOUTINE' or name(LIMS/*)='LIST' ">
                                                <xsl:apply-templates 
select="LIMS/*[1]"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                                <xsl:apply-templates 
mode="default" select="LIMS/*"/>
                                        </xsl:otherwise>
                                </xsl:choose>
                        </body>
                </html>
        </xsl:template>
        <xsl:template match="SUBROUTINE">
        </xsl:template>
        <xsl:template match="LIST">
        </xsl:template>
        <xsl:template match="*">
        </xsl:template>
<xsl:stylesheet>


The input xml document takes the general form of a flat table like structure 
(these are exported xml objects from a data system where the first node is the 
parent table, the other nodes are child tables in the data system).

<?xml version='1.0'?>
<LIMS>
        <LIST/>
        <LIST_ENTRY/>
        <LIST_ENTRY/>
        <LIST_ENTRY/>
</LIMS>



Ultimately I would like to 'call' a named template for specific matched node, 
otherwise 'call' the default template. The purpose of the xsl stylesheet is to 
provide a report that allows users to view the exported xml objects as 
formatted html.

Thanks (to everyone) for your help! (This is such a great list!)

Kind Regards, April


-----Original Message-----
From: Paul Spencer [mailto:xml-dev-list(_at_)boynings(_dot_)co(_dot_)uk]
Sent: Friday, April 25, 2008 7:28 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] fallback to a default template in xsl processing

We would need to see your attempt and the source file to know what you are
doing wrong. The usual problem with default templates is that you pick up
more than you wanted. This can often be avoided by providing a partial path.

Regards

Paul Spencer

-----Original Message-----
From: Daly, April [mailto:april(_at_)dalyweb(_dot_)com]
Sent: 24 April 2008 20:43
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] fallback to a default template in xsl processing


Hi,
Thank you!

I tried that and maybe I didn't set it up correctly....buts the
nodes with 'named' templates (e.g., 'A' or 'B') were processed
twice, once by the template with match='A' and the other by match='*'.
Thanks for your help!
Regards,

April
April L Daly
Daly Web, Inc.
________________________________________
From: Jim Earley [xml(_dot_)jim(_at_)gmail(_dot_)com]
Sent: Thursday, April 24, 2008 3:38 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] fallback to a default template in xsl processing

One approach for this is to use the following:

<xsl:template match="*">
  ...
</xsl:template>

Jim Earley
XML Architect
Flatirons Solutions Corp.



-----Original Message-----
From: Daly, April [mailto:april(_at_)dalyweb(_dot_)com]
Sent: Thursday, April 24, 2008 1:29 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] fallback to a default template in xsl processing

Hi!

I have what I hope is a simple question for the xsl/xpath gurus!


I would like to be able to apply a default template within xsl
1.0 if no match is found.
Currently I'm using an ugly  'brute-force' approach using <xsl:choose>:

<xsl:choose>
   <xsl:when test="name()='A' or name()='B'">
      <xsl:apply-templates mode='namedTemplates' select='.'/>
   </xsl:when>
   <xsl:otherwise>
      <xsl:apply-templates mode='defaultTemplates' select='.'/>
   </xsl:otherwise>
</xsl:choose>


this is a simplfied example, but I hope it shows what I'm trying to do.

Is there a better way to apply a named template if 'found'
otherwise apply a default
template?

Thanks (in advance) for your help!

April
April L Daly
Daly Web, Inc.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--