xsl-list
[Top] [All Lists]

Re: [xsl] Applying a Default Template

2010-11-30 09:13:24
You could use modes:

<xsl:template match="row/*">
<td><xsl:apply-templates select="." mode="specific"/></td>
</xsl:template>

<xsl:template mode="specific" match="money">
<span class="money" onclick="ShowMeMoney()">
<xsl:value-of select="."/>
</span>
</xsl:template>

Michael Kay
Saxonica

On 30/11/2010 14:59, Neil Beddoe wrote:
HI,

I'm transforming some data into XHTML and I was wondering if there's a way to 
apply a template that adds a default format before applying another template 
that applies more specific format.

For example

<results>
     <row>
         <dateTime title="Sent">2009-07-15T14:31:00Z</dateTime>
         <instrument title="Stock" instrumentID="6188" restricted="false">HOLN VX 
Equity</instrument>
         <price title="Price">  66.1</price>
         <percentChange title="PctChg">0</percentChange>
         <money title="Order">6320000</money>
         <proportion title="Filled">0</proportion>
         <money title="Order Size">0</money>
         <price title="Limit">63.2</price>
     </row>
     <row>.
</results>

I need to transform every child of<row>  into a<td>.</td>  element.  I'll also 
want to apply a further template depending on the type of the child.

At the moment I do it like this:
     <xsl:template match="row">
         <tr>
             <xsl:apply-templates>
         </tr>
     </xsl:template>
     <xsl:template match="instrument">
     <td>
         <span>
             <xsl:attribute name="class">
                 <xsl:value-of select="name()"/>
             </xsl:attribute>
             <xsl:value-of select="." />
         </span>
     </td>
     </xsl:template>
     <xsl:template match="money">
         <td>
        <span class="money" onclick="ShowMeMoney()">
             <xsl:value-of select="."/>
        </span>
       </td>
     </xsl:template>
     <xsl:template match="price">
         <td>
                 .etc etc.
         </td>
     </xsl:template>


It  seems inefficient to have to put a<td>  in every one of my individual templates.  Is there 
any way I can apply a template that puts in the<td>  tags for every child of<row>  and then 
applies the individual templates for the types of children of<row>?


What I'd like to be able to do is something like this:
<xsl:call-template name="applyTD">
      <xsl:apply-templates/>
</xsl:call-template>

But I know you can't.

Sorry if the above isn't clear.





.

This message is intended only for the use of the person(s) to whom it is 
addressed. It may contain information which is privileged and confidential. 
Accordingly any unauthorised use is strictly prohibited. If you are not the 
intended recipient, please contact the sender as soon as possible.

It is not intended as an offer or solicitation for the purchase or sale of any 
financial instrument or as an official confirmation of any transaction, unless 
specifically agreed otherwise. All market prices, data and other information 
are not warranted as to completeness or accuracy and are subject to change 
without notice. Any opinions or advice contained in this Internet email are 
subject to the terms and conditions expressed in any applicable governing 
Marble Bar Asset Management LLP's  terms and conditions of business or client 
agreement letter. Any comments or statements made herein do not necessarily 
reflect those of Marble Bar Asset Management LLP.

Marble Bar Asset Management LLP is regulated and authorised by the FSA.

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

<Prev in Thread] Current Thread [Next in Thread>