RE: [xsl] matching multiple times, outputting once?

Subject: RE: [xsl] matching multiple times, outputting once?
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Tue, 6 Nov 2001 09:59:54 -0000
How about a recursive solution:

<xsl:template match="emphasis">
  <xsl:apply-templates select="@*[1]" mode="emphasis">
    <xsl:with-param name="children" select="child::node()"/>
    <xsl:with-param name="other-attributes" select="@*[position()!=1]"/>
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="bold[.='Yes']" mode="emphasis">
  <xsl:with-param name="children"/>
  <xsl:with-param name="other-attributes"/>
  <b>
    <xsl:choose>
    <xsl:when test="$other-attributes">
      <xsl:apply-templates select="$other-attributes[1]" mode="emphasis">
        <xsl:with-param name="children" select="$children"/>
        <xsl:with-param name="other-attributes"
                        select="$other-attributes[position()!=1]"/>
      </xsl:apply-templates>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates select="$children"/>
    </xsl:otherwise>
    </xsl:choose>
  </b>
</xsl:template>

and likewise for the other attributes. (You could put the shared logic into
a named template if you wanted).

Mike Kay



> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of McKeever,
> Marty
> Sent: 05 November 2001 13:18
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] matching multiple times, outputting once?
>
>
> This is really bugging me, because i thought it would be
> simple.  Maybe it
> is, and i'm just having a mental block -- thanks for your help.
>
> Here are 3 possibilities that i have to match for, and 3
> desired outputs:
>
> <emphasis bold="Yes">Hello</emphasis>
> <emphasis bold="Yes" italic="Yes">Hello</emphasis>
> <emphasis bold="Yes" italic="Yes" underline="Yes">Hello</emphasis>
>
> <b>Hello</b>
> <i><b>Hello</b></i>
> <u><i><b>Hello</b></i></u>
>
> and every possible combination thereof.
>
>
> I have had no luck writing an intelligent template rule for
> these -- the
> only way i've found so far is a deeply nested <xsl:choose>
> which takes every
> possible combination into account.  This can't be the best
> way to do this.
>
> Everything else i've tried either matches only one rule, or
> outputs "Hello"
> multiple times, one for each style.
>
> There has to be an elegant solution i'm missing...
>
> (and yes, i know i could easily write this out as <span
> style="font-style:bold,italic;text-decoration:underline">Hello
> </span>, but
> that's not what i'm looking for here.)
>
> TIA!
> marty
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


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


Current Thread