xsl-list
[Top] [All Lists]

Re: [xsl] Copying nested tags and adding attributes

2007-01-30 01:12:46
Hi Graeme,

You can start with a recursive copy template and add a rule to a that adds the alt attribute:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="a">
    <xsl:copy>
      <xsl:attribute name="alt"><xsl:value-of select="."/></xsl:attribute>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


graeme(_dot_)ludwig(_at_)bt(_dot_)com wrote:
I'd like to combine elements of solutions 12 and 8 of Dave Pawson's XSL copying 
FAQ (http://www.dpawson.co.uk/xsl/sect2/N1930.html).
Specifically, I would like to take the XML: <description>See how <b>cans</b> are made into model cars, planes, bikes, etc. at <a href="http://www.tincanmodels.com/"; target="_self">Tin Can Models</a>.
</description>
and transform it into See how <b>cans</b> are made into model cars, planes, bikes, etc. at <a href="http://www.tincanmodels.com/"; alt="Tin Can Models" target="_self">Tin Can Models</a>. i.e. I want to add an alt attribute to the hyperlink and set it to the text of the link itself. The bold attribute should remain unchanged. I know I can use <xsl:template match="description">
  <xsl:copy-of select="node()"/>
</xsl:template>
to get the text out as per solution 12, but am unsure how to generate the extra alt attribute for any <a> elements that occur within the text. I believe I am using an XSLT 1.0 processor. Any help appreciated. Thanks, Graeme.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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