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

Re: Recursive substitution

Subject: Re: Recursive substitution
From: Keith Visco <kvisco@xxxxxxxxx>
Date: Thu, 11 Mar 1999 15:36:30 -0500
xsl template match recursive
Peter,

this works for your example:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"                
                xmlns="http://www.w3.org/TR/REC-html40"> 

<xsl:template match="/">
    <xsl:element name='PARAM'>
         <xsl:attribute name='name'>tree</xsl:attribute>
         <xsl:attribute
name='value'><xsl:apply-templates/></xsl:attribute>
   </xsl:element>   
</xsl:template>

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

<xsl:template match="CGROUP" mode="$">
      $<xsl:apply-templates select=".." mode="$"/>
</xsl:template>

<xsl:template match="CITEM">
   <xsl:apply-templates select=".." mode="$"/>
   <xsl:apply-templates/>|
</xsl:template>

</xsl:stylesheet>

--Keith

-------------------------------------------------


Peter Quarendon wrote:
> 
> Can anyone suggest a way to re-code the following horrible stylesheet
> fragment:
> 
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"
>                 xmlns="http://www.w3.org/TR/REC-html40">
> 
> <xsl:template match="/">
>     <xsl:element name='PARAM'>
>          <xsl:attribute name='name'>tree</xsl:attribute>
>          <xsl:attribute name='value'><xsl:apply-templates/></xsl:attribute>
>    </xsl:element>
> </xsl:template>
> <!-- attempt to put a number of $'s corresponding to the nesting depth -->
> <!-- the mode indicates the depth of nesting:                          -->
> <xsl:template match='CGROUP'><xsl:apply-templates mode='$' select='CGROUP |
> CITEM'/></xsl:template>
> <xsl:template match='CGROUP' mode='$'><xsl:apply-templates mode='$$'
> select='CGROUP | CITEM'/></xsl:template>
> <xsl:template match='CGROUP' mode='$$'><xsl:apply-templates mode='$$$'
> select='CGROUP | CITEM'/></xsl:template>
> <xsl:template match='CGROUP' mode='$$$'><xsl:apply-templates mode='$$$$'
> select='CGROUP | CITEM'/></xsl:template>
> <xsl:template match='CGROUP' mode='$$$$'><xsl:apply-templates mode='$$$$$'
> select='CGROUP | CITEM'/></xsl:template>
> <xsl:template match='CGROUP' mode='$$$$$'>Warning: Tree nesting too
> deep!</xsl:template>
> <!-- output a number of $s according to the mode, followed by the rest of
> the text -->
> <xsl:template match='CITEM'><xsl:apply-templates/>|
> </xsl:template>
> <xsl:template match='CITEM' mode='$'>$<xsl:apply-templates
> select='.'/></xsl:template>
> <xsl:template match='CITEM' mode='$$'>$$<xsl:apply-templates
> select='.'/></xsl:template>
> <xsl:template match='CITEM' mode='$$$'>$$$<xsl:apply-templates
> select='.'/></xsl:template>
> <xsl:template match='CITEM' mode='$$$$'>$$$$<xsl:apply-templates
> select='.'/></xsl:template>
> <xsl:template match='CITEM' mode='$$$$$'>$$$$$<xsl:apply-templates
> select='.'/></xsl:template>
> </xsl:stylesheet>
> 
> which just puts a number of $'s corresponding to the CGROUP depth in front
> of every CITEM.
> For instance from:
> 
> <?xml version="1.0"?>
>     <CGROUP>
>       <CITEM>depth 1</CITEM>
>       <CITEM>depth 1</CITEM>
>       <CGROUP>
>        <CITEM>depth 2</CITEM>
>        <CITEM>depth 2</CITEM>
>       </CGROUP>
>       <CITEM>depth 1</CITEM>
>       <CITEM>depth 1</CITEM>
>     </CGROUP>
> 
> it generate:
> 
> <PARAM name="tree" value="$depth 1|
> $depth 1|
> $$depth 2|
> $$depth 2|
> $depth 1|
> $depth 1|"/>
> 
> I feel there should be a proper way to get the same result (without
> excaping to script).
> 
>  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

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.