xsl-list
[Top] [All Lists]

RE: how to always call a template at the end of xsl:template

2003-10-21 12:58:34
In XSLT 2.0 you can do

<xsl:template match="*" mode="#all" priority="10">
  <xsl:next-match/>
  <xsl:call-template name="logRowId"/>
</xsl:template>

Michael Kay

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Xiaocun Xu
Sent: 21 October 2003 18:19
To: xsl-list
Subject: [xsl] how to always call a template at the end of 
xsl:template


Hi,

  I need to log row ID for error reporting and this
has to be done at end of all rows regardless of
template mode.  The obvious way is to add
<xsl:call-template name="logRowId"/> at end of each of
the <xsl:template match="row"> regardless of mode, the
problem is maintainence as I need to pepper this call
to all row templates (there are a number of row
templates with different modes) and I need to continue
remember add this call at end of each new row template
mode in the future.  Is there a clean way to always
call template logRowId at end of <xsl:template
match="row"> regardless of mode?  Sample source XML
and XSLT below.

thanks,
Xiaocun

Source XML:
<row row="7">
      <cell column="1">host</cell>
      <cell column="3">fsc1_BA1</cell>
      <cell column="4">unacknowledged</cell>
      <cell column="5">rfx</cell>
      <cell column="7">lead</cell>
</row>
<row row="9">
      <cell column="1">respondent</cell>
      <cell column="2">s1</cell>
      <cell column="3">s1_AM1</cell>
      <cell column="4">unacknowledged</cell>
      <cell column="5">rfx</cell>
</row>


XSLT:
<xsl:apply-templates select="//row[(_at_)row &lt; 8]"
mode="host"/>
<xsl:apply-templates select="//row[(_at_)row &gt; 8]" mode="respondent"/>

<xsl:template match="row" mode="host">
      <!-- skip unnecessary details -->
      <xsl:call-template name="logRowId"/>
</xsl:template>
<xsl:template match="row" mode="respondent">
      <!-- skip unnecessary details -->
      <xsl:call-template name="logRowId"/>
</xsl:template>

<!-- log row ID for error reporting -->
<xsl:template name="logRowId">
      <xsl:element name="Logs">
              <xsl:attribute name="rowID"><xsl:value-of 
select="@row"/></xsl:attribute>
      </xsl:element>
</xsl:template>

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search 
http://shopping.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



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