[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: need help with converting attribute into elements

Subject: RE: [xsl] need help with converting attribute into elements
From: Jarno.Elovirta@xxxxxxxxx
Date: Tue, 14 Oct 2003 13:03:14 +0300
x map xsl help
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.