This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Not parsing sub-nodes
- To: "Roshan Sharma" <roshansharma at hotmail dot com>
- Subject: Re: [xsl] Not parsing sub-nodes
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Fri, 9 Mar 2001 09:36:27 +0000
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <F46IucIcCiwvLNcA6oD0000a977@hotmail.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Roshan,
> <xslt:transform xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
version="1.0">>
>
> <xsl:template match="/*">
> <xsl:value-of select="."/>
> <xsl:for-each select="company">
> <xsl:apply-templates select="company"/>
> </xsl:for-each>
> </xsl:template>
>
> <xsl:template match="office">
> <xsl:value-of select="."/>
> <xsl:apply-templates select="office"/>
> </xsl:template>
The first problem is that the namespace prefix that you've declared
for the XSLT namespace ('xslt') isn't the one that you're using on the
templates in the stylesheet (where you're using 'xsl' instead). Those
need to be in sync.
The second thing is that you seem to be misunderstanding how
xsl:apply-templates works. The path that you give in the select
attribute of xsl:apply-templates is resolved relative to the *current
node*.
In the xsl:for-each in the first template, then the current node is a
'company' element (a child of the document element, which in your case
seems to be company 'Uno'). The company elements that are iterated
over by the xsl:for-each are therefore the companies 'Duo', 'Tres' and
'Quatro'. The xsl:apply-templates then applies templates to the
company element children of these company elements - there aren't any,
so no templates get applied.
In the xsl:template for the office, again you apply templates to the
'office' children of the current office. You don't appear to have
nested offices inside one another, so again the processor won't find
anything to apply templates to.
What you're after is something along the lines of:
<xsl:template match="company">
<!-- give the name of the company -->
<xsl:value-of select="@name" />
<!-- apply templates to its office child -->
<xsl:apply-templates select="office" />
<!-- apply templates to any company children -->
<xsl:apply-templates select="company" />
</xsl:template>
<xsl:template match="office">
<!-- give the location of the office -->
<xsl:value-of select="@location" />
</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