This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: matching multiple times, outputting once?
Hello Marty,
gee u kicked off the tail recursion *dissertation*, hehe though i like the
haskell stuff DN is digging into.
----- Original Message -----
From: "Goetz Bock" <bock@blacknet.de>
been off list for awhile and i see that u have already a few solutions, i
like the elegance of Goetz Bock solution.
here is yet another slight variation;
xsl
---------------------------------------------------------------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:output indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*[@*]">
<xsl:call-template name="a2e">
<xsl:with-param name="node" select="."/>
<xsl:with-param name="attpos" select="1"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="a2e">
<xsl:param name="node" select="/.."/>
<xsl:param name="attpos" select="/.."/>
<xsl:choose>
<xsl:when test="(count($node//@*)+1) > $attpos">
<xsl:variable name="attribute"
select="name($node/@*[position()=$attpos])"/>
<xsl:element name="{$attribute}">
<xsl:call-template name="a2e">
<xsl:with-param name="node" select="$node"/>
<xsl:with-param name="attpos" select="$attpos+1"/>
</xsl:call-template>
</xsl:element>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$node"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
--------------------------------------------
xml
---------------------------------------------
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="test2.xsl" ?>
<contents>
<emphasis bold="yes" italic="yes" >Hello</emphasis><br />
<emphasis bold="yes" italic="yes" >Hello</emphasis><br />
<emphasis underline="yes" italic="yes" bold="yes">Hello</emphasis><br />
<test test="yes">aaaaaaaaaaaaaa</test>
</contents>
--------------------------------------------
essentially this template is an attribute to element transform, it could
easily be adaptable for your purposes.
one of the benefits is that u could use the att name as the element
<contents>
<emphasis b="yes" i="yes" >Hello</emphasis><br />
<emphasis b="yes" i="yes" >Hello</emphasis><br />
<emphasis u="yes" i="yes" b="yes">Hello</emphasis><br />
</contents>
oh well, now i look at the tail recursion fun
chow, jim fuller
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list