[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: simple XPath question

Subject: RE: simple XPath question
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Mon, 2 Jul 2001 23:35:41 +0100
xpath select first item
Both of the <country> elements are the first <country> within their parent
element, so they both match the pattern match="country[1]". If you want to
match a country that is within the first <item> in a warehouse, you could
write match="warehouse/item[1]/country".

Mike Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Chris Nolte
> Sent: 02 July 2001 21:47
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  simple XPath question
>
>
> 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:
> <?xml version='1.0'?>
> <warehouse>
>   <item>
>     <name>orange</name>
>     <country>US</country>
>   </item>
>   <item>
>     <name>ice wine</name>
>     <country>Canada</country>
>   </item>
> </warehouse>
>
> And here is the stylesheet:
> <?xml version='1.0'?>
> <xsl:stylesheet version='1.0'
>   xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
>   <xsl:output method='xml' indent='yes'/>
>
> <xsl:template match='/'>
>   <xsl:apply-templates/>
> </xsl:template>
>
> <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?
>
> Chris
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.