Re: [xsl] Editing URLs

Subject: Re: [xsl] Editing URLs
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 28 Apr 2003 18:45:14 -0400
John,

Given source like:

<a href="maps.maps.html">Map of maps</a>

you want XSLT something like:

<xsl:template match="*|@*">
  <!-- this is an identity template that will match your 'a'
       along with everything else -->
  <xsl:copy>
    <xsl:apply-templates select="@*|*"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="@href">
  <!-- this template will match the @href attribute, and has a
       higher precedence than the other (so is preferred) -->
  <xsl:copy>
    <xsl:text>http://</xsl:text>
    <xsl:value-of select="."/>
  </xsl:copy>
</xsl:template>

or, more simply (but not rolled into the identity transform),

<xsl:template match="a">
  <a href="http://{@href}";>
    <xsl:apply-templates select="*"/>
  </a>
</xsl:template>

I hope that helps--
Wendell

At 05:09 PM 4/28/2003, you wrote:
I am writing an XSLT that I want to edit HREFs. Currently my XHTML source files do not include http:// in the cross-references. They are phrased as "<a href="maps.maps.html">blah, blah, blah</a>". Because of my process I need to add in "http://"; at the beginning of the URLs. For the life of me, I cannot figure out how to make this work. Any suggestions?


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