This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: processing different nodes
- To: "sony sebastian" <sony50 at hotmail dot com>
- Subject: Re: [xsl] processing different nodes
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Thu, 29 Mar 2001 14:06:55 +0100
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <F7TFur2iz2Mb1s7nlT200002aaa@hotmail.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Sony,
> I had posted a similar question before. I am afraid the XML I had
> did not reflect the complexity and was wrong.
Am I right that the only real difference is that the 'def' attribute
points to a pardef element, and it's whether the pardef element has a
list attribute that indicates whether it should be a bulleted list or
not?
The first thing to do is to set up a key so that you can quickly get
from a 'def' attribute value to the relevant pardef element:
<xsl:key name="pardef-by-id" match="pardef" use="id" />
With that key in place, you can get the pardef element associated with
a particular id with:
key('pardef-by-id', $def)
>From there, you can find out whether it's supposed to be a list with:
key('pardef-by-id', $def)/@list = 'bullet'
As I discussed last time, given a particular par element, you can find
the relevant definition by looking at its own 'def' attribute or, if
it doesn't have one, the nearest preceding sibling par element that
has a 'def' attribute. You can get this 'def' attribute with:
@def | preceding-sibling::par[@def][1]/@def[not(current()/@def)]
or:
(@def | preceding-sibling::par[@def][1]/@def)[last()]
this gets the last 'def' attribute in document order. So within a
template that matches a par element, you can assign that 'def'
attribute to a variable, and then use it to get the relevant pardef
element, check whether it's supposed to be a list, and give a * if it
is:
<xsl:template match="par">
<xsl:variable name="def"
select="(@def | preceding-sibling::par[@def][1]/@def)[last()]" />
<xsl:variable name="bullet"
select="key('pardef-by-id', $def)/@list = 'bullet'" />
<xsl:if test="$bullet">*</xsl:if>
<xsl:apply-templates />
</xsl:template>
Or you can still walk through the list one par element at a time, as I
described in the last email. Again, use the key to find the relevant
pardef to work out what to do.
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list