Re: [xsl] Unwrapping trees

Subject: Re: [xsl] Unwrapping trees
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 13 Jun 2002 14:23:41 -0400
Norm --

How about:

<xsl:template match="a"><!-- just letting it default -->
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="a//text()">
  <a href="{ancestor::a[1]/@href}">
    <xsl:value-of select="."/>
  </a>
</xsl:template>

...and just copying the span...?

Cheers,
Wendell


At 10:56 AM 6/13/2002, you wrote:
Has anyone written the XSLT required to "unwrap" nested links?

I'd like to turn, for example:

<p>
  text
  <a href="1">
    text
    <span>
      <a href="2">test</a>
      text
    </span>
    text
  </a>
  text
</p>

into

<p>
  text
  <a href="1">
    text
    <span/>
  </a>
  <span>
    <a href="2">test</a>
    text
  </span>
  <a href="1">
    text
  </a>
  text
</p>

With extra bonus points for discarding the empty span (if it doesn't
have an ID :-)

                                        Be seeing you,
                                          norm

--
Norman.Walsh@xxxxxxx   | Wisdom is only a comparative quality, it will
XML Standards Engineer | not bear a single definition.--Marquess of
XML Technology Center  | Halifax
Sun Microsystems, Inc. |

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


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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



Current Thread