Subject: Re: [xsl] Matching and changing attributes. From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Wed, 30 May 2001 14:09:39 +0100 |
I have a situtation where I would like add a few rules to clean up an XHTML-document which uses too many @class attributes.
<xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
I know that I can match a node with a class-attribute with a specific text, but this means that other rules cannot come in play with that node, and it would be most intuitive to work on the attribute level.
So my question is,
Given a node with a class attribute, like
<mynode class="somestring"/>
how do I write a template that is fired when <xsl:apply-templates match="@*"> is executed, and optionally change the attribute giving the result
<mynode class="someotherstring">
You mean <xsl:apply-templates select="@*"/> ^^^^^^ Or its variant (as in the identity transform)
<xsl:template match="@*"> <xsl:value-of select="."/> </xsl:template>
<xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy>
<xsl:template match="@class"> <xsl:attribute name="class"> <xsl:choose> <xsl:when test=".='badvalue'"> <xsl:text>goodvalue</xsl:text> </xsl:when> <xsl:when test=".='otherbadvalue'"> <xsl:text>othergoodvalue</xsl:text> </xsl:when> <xsl:otherwise> <xsl:value-of select="."/> </xsl:otherwise> </xsl:choose> </xsl:attribute> </xsl:template>
<xsl:when test=".='badvalue'"> <xsl:value-of select="local-name(..)"/> </xsl:when>
(PS: If anyone can point me to a page about how to use both this list and Outlook while keeping my sanity, I will appreciate it).
Good luck, Wendell
====================================================================== 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 ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] generic method of getting, Chris Bayes | Thread | [xsl] Matching and changing attribu, Thorbjørn Ravn Ander |
[xsl] email and XSL, Edward Kennedy | Date | RE: [xsl] xsl:sort - sorting accord, Bryan Tulloch |
Month |