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

Re: matching multiple times, outputting once?

Subject: Re: matching multiple times, outputting once?
From: "cutlass" <cutlass@xxxxxxxxxxx>
Date: Thu, 8 Nov 2001 23:06:33 -0000
tail recursive dissertation
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@xxxxxxxxxxx>

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


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.