You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Evgeniy Strokin <ev...@yahoo.com> on 2002/05/03 21:23:28 UTC

How I can know level of nesting of each descendant?

Hi,
I have code:
<script>
<xsl:for-each select="ProductMetadata">
<xsl:variable name="prod" select="."/>
var prod_<xsl:value-of select="$prod/@product"/>=new
Array(<xsl:value-of select="count(descendant::*)"/>);
	<xsl:for-each select="descendant::*">
	prod_<xsl:value-of
select="$prod/@product"/>[<xsl:value-of
select="position()"/>]="<xsl:value-of
select="@mnemonic"/>";
	</xsl:for-each>
</xsl:for-each>
</script>
How I can know level of nesting of each descendant? 
Actually I want to put how many &nbsp; before
<xsl:value-of select="@mnemonic"/> what level of
nesting is. 
For example:
If I have XML like:
<root>
<ProductMetadata product="pr1">
<prop1 mnemonic="1">	
<prop2 mnemonic="2"/>
<prop3 mnemonic="3"/>
</prop1>
<prop4 mnemonic="4"/>
</ProductMetadata>
</root>
I want result like:
var prod_pr1=new Array(4);
prod_pr1[0]="1";
prod_pr1[1]="&nbsp;2";
prod_pr1[2]="&nbsp;3";
prod_pr1[3]="4";

Is it possible at all?
Thanks,
Jenya


__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

Re: How I can know level of nesting of each descendant?

Posted by Jean Croteau <cr...@cognicase.ca>.
I think you can do this using recursive template.  Just past the indent to
the child section.  Here is an example, hope this helps.

<xsl:template match="section">
    <xsl:param name="indent"/>
    <xsl:value-of select="$indent"/><xsl:value-of select="something"/><br/>
    <xsl:apply-templates select="section">
        <xsl:with-param name="indent" select="concat($indent,"&#160;")"/>
    </xsl:apply-templates>
</xsl:template>

You could also use <xsl:call-template> I think.

----- Original Message -----
From: "Evgeniy Strokin" <ev...@yahoo.com>
To: <xa...@xml.apache.org>
Sent: Friday, May 03, 2002 3:23 PM
Subject: How I can know level of nesting of each descendant?


> Hi,
> I have code:
> <script>
> <xsl:for-each select="ProductMetadata">
> <xsl:variable name="prod" select="."/>
> var prod_<xsl:value-of select="$prod/@product"/>=new
> Array(<xsl:value-of select="count(descendant::*)"/>);
> <xsl:for-each select="descendant::*">
> prod_<xsl:value-of
> select="$prod/@product"/>[<xsl:value-of
> select="position()"/>]="<xsl:value-of
> select="@mnemonic"/>";
> </xsl:for-each>
> </xsl:for-each>
> </script>
> How I can know level of nesting of each descendant?
> Actually I want to put how many &nbsp; before
> <xsl:value-of select="@mnemonic"/> what level of
> nesting is.
> For example:
> If I have XML like:
> <root>
> <ProductMetadata product="pr1">
> <prop1 mnemonic="1">
> <prop2 mnemonic="2"/>
> <prop3 mnemonic="3"/>
> </prop1>
> <prop4 mnemonic="4"/>
> </ProductMetadata>
> </root>
> I want result like:
> var prod_pr1=new Array(4);
> prod_pr1[0]="1";
> prod_pr1[1]="&nbsp;2";
> prod_pr1[2]="&nbsp;3";
> prod_pr1[3]="4";
>
> Is it possible at all?
> Thanks,
> Jenya
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Health - your guide to health and wellness
> http://health.yahoo.com
>