|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Re: recursive template grabbing nested elements...
Jeni Tennison wrote:
[snip]
> I should think Dimitre will show you an alternative that is not as
> closely coupled with your source XML, using one of his generic
> templates.
As Jeni suggested, I'm including finding the deepest "tab" element by using the
generic max() template.
The main thing to note is, you only have to specify the "comparison template" and
this gives you automatically the whole solution -- no need to re-program for the
N-th time your max() template, no possibility at all to make any mistakes as this
additional coding simply does not exist any more.
This is an almost mechanical, straightforward activity, taking only a couple of
minutes.
Your source xml (genericMath.minmax.data.2.xml):
----------------------------------------------
<tabs>
<tab state="on" id="1.1">
<tab state="off" id="1.1.1">
</tab>
<tab state="on" id="1.1.2">
</tab>
</tab>
<tab state="off" id="1.2">
</tab>
</tabs>
The stylesheet (genericMath.minmax.2.xsl):
-----------------------------------------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:gt-deeper="gt-deeper"
exclude-result-prefixes="gt-deeper"
>
<gt-deeper:node/>
<xsl:variable name="gt-node" select="document('')//gt-deeper:*"/>
<xsl:output omit-xml-declaration="yes"/>
<!-- You can download the following file at
http://www.vbxml.com/downloads/default.asp?id=v2001611171627 -->
<xsl:include href="genericMath.minmax.template.xsl"/>
<xsl:variable name="nodes" select="//tab"/>
<xsl:template match="/">
<xsl:variable name="vMax1">
<xsl:call-template name="pMax">
<xsl:with-param name="nodes" select="$nodes"/>
<xsl:with-param name="start" select="1"/>
<xsl:with-param name="end" select="count($nodes)"/>
<xsl:with-param name="greaterTemplateUID" select="$gt-node"/>
</xsl:call-template>
</xsl:variable>
<Result>
<xsl:text>
</xsl:text>
<xsl:value-of select="concat('Max1: nodes[',$vMax1, '] = ',
$nodes[position()=$vMax1]/@id )"/>
<xsl:text>
</xsl:text>
</Result>
</xsl:template>
<xsl:template match="*[namespace-uri() = 'gt-deeper']">
<xsl:param name="n1" select="/.."/>
<xsl:param name="n2" select="/.."/>
<xsl:value-of select="count($n1/ancestor::*) > count($n2/ancestor::*)"/>
</xsl:template>
</xsl:stylesheet>
Result:
------
<Result>
Max1: nodes[2] = 1.1.1
</Result>
Cheers,
Dimitre Novatchev.
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
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








