This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Fwd: BOUNCE xsl-list@lists.mulberrytech.com: Non-member submission from ["Jeni Tennison" <jeni@tennison.2ndmail.com>]


In the meantime, the stand-in XSL-List owner has to forward Jeni's messages....

>Date: Tue, 8 May 2001 04:36:01 -0400 (EDT)
>From: owner-xsl-list@lists.mulberrytech.com
>To: xsl-list-approval@lists.mulberrytech.com
>Subject: BOUNCE xsl-list@lists.mulberrytech.com:    Non-member submission 
>from ["Jeni Tennison" <jeni@tennison.2ndmail.com>]
>X-Loop-Detect: 1
>
> >From jeni@tennison.2ndmail.com  Tue May  8 04:35:51 2001
>Received: from www.2ndmail.com (2ndmail.com [209.75.7.64])
>         by biglist.com (8.8.8/8.8.5/BL-2) with SMTP id EAA12401
>         for <XSL-List@lists.mulberrytech.com>; Tue, 8 May 2001 04:35:51 
> -0400 (EDT)
>Date: Tue, 8 May 2001 04:35:51 -0400 (EDT)
>Message-Id: <200105080835.EAA12401@biglist.com>
>Received: (qmail 71263 invoked from network); 8 May 2001 08:37:08 -0000
>Received: from localhost (HELO 2ndmail.com) (127.0.0.1)
>   by localhost with SMTP; 8 May 2001 08:37:08 -0000
>From: "Jeni Tennison" <jeni@tennison.2ndmail.com>
>To: "Joakim Norlov" <jn@uniscope.co.jp>
>Cc: "XSL Mailing list" <XSL-List@lists.mulberrytech.com>
>Importance: Normal
>X-Mailer: VisualMail 3.05 ( http://www.mintersoft.com/visualmail )
>Subject: Re: [xsl] How to avoid applying templates several times to the 
>same descendant
>Mime-Version: 1.0
>Content-type: text/plain; charset="iso-8859-1"
>
>Hi Joakim,
>
> > My problem is: How can I select to "execute" only selected nodes,
> > when I don't know what level they are at, or what names they have.
> > In addition to the "spec" above, there are a bunch of other
> > templates that also have to apply to the elements in question.
>
>I think that the answer is 'use modes'.  Moded templates allow you to
>apply several different templates to the same nodes in different
>circumstances.  I'll show you the solution to the problem that you
>gave (thanks for providing, input, output and some XSLT, btw - very
>helpful) which will hopefully demonstrate how to use them in this
>problem.
>
>The general approach is to apply templates to the top-level ATLAS
>element multiple times - once for each of the unique @ATTR values,
>each time making a copy of the ATLAS element and its relevant
>children. Because I also want to apply templates to the ATLAS element
>as a controlling template, I use the 'copy' mode to distinguish
>between the normal processing flow and the special 'copying' process.
>I use a parameter to pass in the @ATTR value that I'm currently making
>a copy for.
>
>I've used the same key as you:
>
><xsl:key name="UniqueATTR" match="*[@ATTR]" use="@ATTR"/>
>
>The top-level template has to control the process, applying templates
>to the document ATLAS element for each of the unique @ATTR values.  I
>loop over the unique values, just as you did, but apply templates to
>the ATLAS element in copy mode and pass the @ATTR value as a
>parameter.
>
><xsl:template match="ATLAS">
>    <xsl:variable name="atlas" select="." />
>    <xsl:for-each select="//*[@ATTR]
>                             [generate-id() =
>                              generate-id(key('UniqueATTR', @ATTR)[1])]">
>       <xsl:apply-templates select="$atlas" mode="copy">
>          <xsl:with-param name="attr" select="@ATTR" />
>       </xsl:apply-templates>
>    </xsl:for-each>
></xsl:template>
>
>The next template is applied as a result.  It matches the ATLAS
>element in copy mode and accepts the $attr parameter.  It creates a
>ATLAS element with the relevant @ATTR value (using literal result
>elements rather than xsl:element/xsl:attribute to make things
>clearer).  Then it applies templates to *its* children, again in
>'copy' mode and still passing the $attr parameter through.
>
><xsl:template match="ATLAS" mode="copy">
>    <xsl:param name="attr" />
>    <ATLAS ATTR="{$attr}">
>       <xsl:apply-templates mode="copy">
>          <xsl:with-param name="attr" select="$attr" />
>       </xsl:apply-templates>
>    </ATLAS>
></xsl:template>
>
>The final template is applied on these child elements.  Again it's in
>copy mode with an $attr parameter.  Within, I test whether the element
>I'm looking at either hasn't got an @ATTR attribute or has one with a
>value equal to the $attr parameter.  In either of those cases, I make
>a copy of it and then move on recursively to the next layer in the
>hierarchy.
>
><xsl:template match="*" mode="copy">
>    <xsl:param name="attr" />
>    <xsl:if test="not(@ATTR) or @ATTR = $attr">
>       <xsl:copy>
>          <xsl:copy-of select="@*" />
>          <xsl:apply-templates mode="copy">
>             <xsl:with-param name="attr" select="$attr" />
>          </xsl:apply-templates>
>       </xsl:copy>
>    </xsl:if>
></xsl:template>
>
>I hope that helps,
>
>Jeni
>
>(this is a temporary address due to mailing problems - please use 
>mail@jenitennison.com)
>
>Jeni Tennison
>http://www.jenitennison.com
>
>======================================================
>
>The most personalized email addresses available!
>at: http://www.2ndmail.com
>Say goodbye to that boring email address.
>
>======================================================


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]