Re: [xsl] selecting a element without it's child element

Subject: Re: [xsl] selecting a element without it's child element
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Wed, 10 Nov 2010 12:05:04 +0000
On 10/11/2010 11:03, srinivasan.p@xxxxxxxxxx wrote:
Thanks Pankaj, its working fine now.



<xsl:variable name="filename"><xsl:value-of
select="book/title/text()[1]"/></xsl:variable>

--Pankaj


That's not a good solution, however. It's dependent on properties of your input that might not always hold, and that weren't specified in your description of the problem - notably, that all the text of the title other than the indexterm is in a single text node that is an immediate child of the title element. Pankaj has seen one example of your input data, and leapt to the conclusion that all other examples will be the same. You've run it on a single test case (I imagine), and concluded that it's correct because it works on that test case.


Learn to use template rules: they are the right way to tackle this kind of problem. In fact, they are the right way to tackle nearly every XSLT problem.

Michael Kay
Saxonica

Current Thread