RE: [xsl] why doesn't 'self::NODE' work?

Subject: RE: [xsl] why doesn't 'self::NODE' work?
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Tue, 15 Apr 2003 09:33:27 -0400
[Wright, Steve]
>I am trying desparately to obtain the following input from 
> the below xml
> tree:
>
[snip]
> 
> This is the XPATH expression that I am using:
> --------------------------------------------------------
> <xsl:template match="PARA/LINK">
> 	<xsl:value-of select="self::LINK" />
> </xsl:template>
> --------------------------------------------------------
> 
> --------------------------------------------------------
> This is the (undesired) output that I am getting:
> --------------------------------------------------------
> Figure The Cell Membrane 3-3
> 
> --------------------------------------------------------
> 

In addition to the other answers you have received, let me add a few
things.  First of all, your template is not returning the results you
see.  It may very well not even be called.  Instead, your results are
being returned by the xslt default template, which returns the text
content of an element of there are no other templates available.

You can demonstrate this by adding a template that matches all elements
but does nothing -

<xsl:template match='*'/>

Of course, I had to make an assumption about how you were trying to
invoke your template, but when I added this null template, the output
vanished.

To work out the answer, you really have to say what you want to get.  We
have to assume that you want to ignore the text content of any elements
that are children of LINK.  Is that right?

You also have to make sure that your template gets invoked.  Assuming
that PARA is the document element (the top-level one), you could write 

<xsl:template match='/PARA'>
   <xsl:apply-templates/>
</xsl:template>

<xsl:template match="LINK">
	<xsl:copy-of select="text()" />
</xsl:template>

Even simpler would be 

xsl:template match='/PARA'>
   <xsl:apply-templates select="LINK/text()"/>
</xsl:template>

In these examples, the built-in default template does not get invoked
because you have provided a template to handle the nodes of interest.

What form you end up choosing would depend on what else you want to do
besides display the figure caption.

Cheers,

Tom P

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread