|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Recursive substitution
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








