Subject: Re: [xsl] simple XPath question From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Mon, 02 Jul 2001 18:45:32 +0100 |
I am trying to work through an example in Khun Yee Fung's XSLT book. It is not giving me the solution he claims it should, but I do not understand why not.
Here is the sample XML: [snipped] And here is the stylesheet: [more snipped] <xsl:template match='warehouse'> <storage> <xsl:apply-templates select='item/country'/> </storage> </xsl:template>
<xsl:template match='country'> <xsl:copy-of select='.'/> </xsl:template>
<xsl:template match='country[1]'> <first-country> <xsl:copy-of select='.'/> </first-country> </xsl:template>
</xsl:stylesheet>
The output I am getting [using Saxon] is: <?xml version="1.0" encoding="utf-8"?> <storage> <first-country> <country>US</country> </first-country> <first-country> <country>Canada</country> </first-country> </storage>
i.e., the first-country template is getting matched both times, even though the XPath expression uses country[1].
What seems strange to me is that when I include the line <xsl:copy-of select='position()'/> at the beginning of the template matching country[1], I get a 1 and a 2.
I believe I am supposed to get: <storage> <first-country> <country>US</country> </first-country> <country>Canada</country> </storage>
Am I doing something wrong, or is the example in Fung's book (Chapter 6, p. 149) wrong? How should the stylesheet be structured to get the intended output?
Hope that helps, Wendell
Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] simple XPath question, Chris Nolte | Thread | Re: [xsl] simple XPath question, Wendell Piez |
Re: [xsl] error xsl/java, Brais | Date | Re: [xsl] Retrieving XML document's, Wendell Piez |
Month |