xsl-list
[Top] [All Lists]

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

2008-04-25 07:33:07
Hi,

I got your suggestions to work (thanks) and while the req. to select a named 
template for certain matched nodes and a default template for all others is 
true...there is of course more :-)

each xml input file representents a single object in the system. the object is 
table based (e.g., parent<-children<-grandchildren<-...)

the default template writes an html table for each LIMS/* (table)

the other templates also tranverse each LIMS/* node but the output is tailored 
for type of object

here in lies more brute force (awkward) xpath:

        <xsl:template match="LIST">
                <xsl:param name="ListName">
                        <xsl:value-of select="NAME"/>
                </xsl:param>

                <xsl:element name="table">
                        <xsl:element name="tbody">
                                <xsl:for-each select="node()">
                                        <xsl:element name="tr">
                                                <xsl:element name="td">
                                                        <xsl:value-of 
select="name()"/>
                                                </xsl:element>
                                                <xsl:element name="td">
                                                        <xsl:value-of 
select="."/>
                                                </xsl:element>
                                        </xsl:element>
                                </xsl:for-each>
                        </xsl:element>
                </xsl:element>
                <xsl:element name="table">
                        <xsl:element name="tbody">
                                <xsl:for-each 
select="//LIST_ENTRY[LIST=$ListName]">
                                        <xsl:sort select="ORDER_NUMBER" 
data-type="number"/>
                                        <xsl:element name="tr">
                                                <xsl:element name="td">
                                                        <xsl:value-of 
select="ORDER_NUMBER"/>
                                                </xsl:element>
                                                <xsl:element name="td">
                                                        <xsl:value-of 
select="NAME"/>
                                                </xsl:element>
                                                <xsl:element name="td">
                                                        <xsl:value-of 
select="VALUE"/>
                                                </xsl:element>
                                        </xsl:element>
                                </xsl:for-each>
                        </xsl:element>
                </xsl:element>
        </xsl:template>


        <xsl:template  match="*">
                <xsl:element name="div">
                        <xsl:element name="h2">
                                <xsl:value-of select="name()"/>
                        </xsl:element>
                        <xsl:element name="table">
                                <xsl:element name="tbody">
                                        <xsl:element name="tr">
                                                <xsl:element name="th">Field 
Name</xsl:element>
                                                <xsl:element name="th">Field 
Value</xsl:element>
                                        </xsl:element>
                                        <xsl:for-each select="node()">
                                                <xsl:call-template 
name="lwNodeRow"/>
                                        </xsl:for-each>
                                </xsl:element>
                        </xsl:element>
                </xsl:element>
        </xsl:template>


The first node under LIMS is always unique (i.e., the parent table), the other 
nodes the child tables


what would be nice :-) is for each unique name( LIMS/* ) other then the LIMS/[1]
to be a table with field names as columns and the rows the (child table) table 
records

I don't know if that makes sense, but I'm in good shape with your suggestion 
for my presentation (many thanks!)

best, april

-----Original Message-----
From: David Carlisle [mailto:davidc(_at_)nag(_dot_)co(_dot_)uk]
Sent: Friday, April 25, 2008 10:08 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] fallback to a default template in xsl processing



is it ok to just keep adding to the expression? e.g.,

OK as in it'll work, yes. On the other hand I was just guessing what
your real requirement is from the example you posted and I suspect that
that is not it.

Is it really the case that if the first element is SUBROUTINE (or
friends) you want to silently discard all following elements, but if
SUBROUTINE (or friends) occurs in any other position you want to process
all elements in document order. If that is what you need, then, as you
see, you can have that; but it seems a slightly strange requirement
which is reflected in the slightly awkward coding of a long bunch of
self::SUBROUTINE or self::LIST or ...  tests.

David

--~------------------------------------------------------------------
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>
--~--