Re: [xsl] need help with converting attribute into elements

Subject: Re: [xsl] need help with converting attribute into elements
From: Aleš Peregrin <ales.peregrin@xxxxxxxxxx>
Date: Tue, 14 Oct 2003 13:05:54 +0200
Hi,
thanx a lot. Now this is what I call "sophisticated solution"! I'm a XSLT
beginner, so I don't understand some details, but I got the point.

thanx again

Ales Peregrin

----- Original Message -----
From: <Jarno.Elovirta@xxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Tuesday, October 14, 2003 12:03 PM
X-Scanned: By Symantec Anti-Virus Scan Engine
Subject: Re: [xsl] need help with converting attribute into elements


> Hi,
>
> > Yes, that would probably work, but I am required not to use CSS.
>
> Sigh.
>
> How about
>
> <xsl:stylesheet version="1.0"
>                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>                 xmlns:x="x"
>                 exclude-result-prefixes="x">
>   <xsl:template match="text">
>     <font>
>       <xsl:call-template name="decorator"/>
>     </font>
>   </xsl:template>
>   <xsl:template name="decorator">
>     <xsl:param name="node-set" select="@*"/>
>     <xsl:choose>
>       <xsl:when test="$node-set[1] = 'true'">
>         <xsl:element name="{$map[@key = name($node-set[1])]/@value}">
>           <xsl:call-template name="decorator">
>             <xsl:with-param name="node-set"
select="$node-set[not(position() = 1)]"/>
>           </xsl:call-template>
>         </xsl:element>
>       </xsl:when>
>       <xsl:when test="$node-set">
>         <xsl:call-template name="decorator">
>           <xsl:with-param name="node-set" select="$node-set[not(position()
= 1)]"/>
>         </xsl:call-template>
>       </xsl:when>
>       <xsl:otherwise>
>         <xsl:apply-templates/>
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:template>
>   <xsl:variable name="map" select="document('')/*/x:map/item"/>
>   <x:map>
>     <item key="bold" value="b"/>
>     <item key="italic" value="i"/>
>     <item key="underline" value="u"/>
>   </x:map>
> </xsl:stylesheet>
>
> A tad verbose, granted, but fairly easy to customize to take care for
blink and so forth. Or, if you wish to go the CSS-way when
those-who-require-silly-things come to their senses,
>
> <xsl:stylesheet version="1.0"
>                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>                 xmlns:x="x"
>                 exclude-result-prefixes="x">
>   <xsl:template match="text">
>     <span>
>       <xsl:attribute name="style">
>         <xsl:for-each select="@*[. = 'true']">
>           <xsl:value-of select="$map[@key = name(current())]/@value"/>;
>           <xsl:text/>
>         </xsl:for-each>
>       </xsl:attribute>
>       <xsl:apply-templates/>
>     </span>
>   </xsl:template>
>   <xsl:variable name="map" select="document('')/*/x:map/item"/>
>   <x:map>
>     <item key="bold" value="font-weight:bold"/>
>     <item key="italic" value="font-style:italic"/>
>     <item key="underline" value="text-decoration:underline"/>
>   </x:map>
> </xsl:stylesheet>
>
> Of course, use xsl:choose structure instead of a mapping table if it feels
more natural to you. Or should that be "--for you--"?
>
> Cheers,
>
> Jarno - Conjure One: Sleep (Ian Van Dahl Mix)
>
>  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