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

Subject: RE: [xsl] need help with converting attribute into elements
From: Jeff Beadle <Jbeadle@xxxxxxxx>
Date: Tue, 14 Oct 2003 08:29:11 -0400
Hey Ales,

I'm coming into this thread a bit late, but here's an approach that has no
conditional logic and should be easy to extend.

This approach assumes that the order of the nesting doesn't matter ... which
with html's "b", "i", and "u" elements that's true.

You build in the ordering logic--if needed--into the "the-list" variable.


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" exclude-result-prefixes="msxsl"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
	xmlns:msxsl="urn:schemas-microsoft-com:xslt">

<xsl:template match="/">
	<xsl:apply-templates/>
</xsl:template>

<xsl:template match="text">
   <xsl:variable name="the-list">
      <xsl:for-each select="@*[.='true']">
         <xsl:element name="{name()}"/>
      </xsl:for-each>
      <the-value><xsl:value-of select="."/></the-value>
   </xsl:variable>
   <font>
      <xsl:apply-templates select="msxsl:node-set($the-list)/child::*[1]"/>
   </font>
</xsl:template>

<xsl:template match="bold">
   <b>
      <xsl:apply-templates select="following-sibling::*[1]"/>
   </b>
</xsl:template>

<xsl:template match="italic">
   <i>
      <xsl:apply-templates select="following-sibling::*[1]"/>
   </i>
</xsl:template>

<xsl:template match="underline">
   <u>
      <xsl:apply-templates select="following-sibling::*[1]"/>
   </u>
</xsl:template>

<xsl:template match="the-value">
   <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>


HTH,
Jeff

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread