This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: XSL-loop
- To: "Mark Gray" <mark at verdensnavle dot com>
- Subject: Re: [xsl] XSL-loop
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Fri, 23 Mar 2001 11:44:56 +0000
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <002a01c0b2cc$cd23c580$4ae8c0c3@eggym.dk>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Mark,
> In my DTD i've created a P-tag. It can contain many different
> elements - also other P's. A P-element has an attribute called
> Title. It contains the title of a block of text (p for paragraph!).
> I would like to display the titles of the different P-elements with
> a different headersize for each title depending on its position in
> the XML-tree (how many P-ancestors does it have).
You can find out how many P ancestor elements you have with the XPath:
count(ancestor::P)
This gets all the P elements that are ancestors of this one and counts
them.
You can create an element name dynamically using an
attribute-value-template as the value of the name attribute on
xsl:element. For example if $level holds the number that you want,
you can create HTML headings of different levels with:
<xsl:element name="h{$level}">
...
</xsl:element>
Putting this together, you can use:
<xsl:template match="P">
<xsl:element name="h{count(ancestor::P) + 1}">
<xsl:value-of select="@Title" />
</xsl:element>
...
</xsl:template>
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list