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

Re: xpath help?

Subject: Re: xpath help?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 09 Jul 2003 13:53:01 -0400
ots map xml download
At 2003-07-09 10:15 -0700, Paul Tomsic wrote:
How do I get all possible sizes from the following XML
using only one xPath given the criteria of
ot[@id = 2 or @id  = 3] and ct[@id = 1]?

so, I'd want size id's = (2,4)??

I hope the answer below helps ... not sure what aspect of XPath you were having difficulty to understand, so it is not easy to guide you in learning what "went wrong" in what you were trying to do.


................... Ken

T:\ftemp>type tomsic.xml
<hls>
  <hl>
    <ots>
       <ot id="2"/>
       <ot id="3"/>
    </ots>
    <cts>
       <ct id="1"/>
       <ct id="5"/>
    </cts>
    <sizes>
       <size id="2"/>
       <size id="4"/>
    </sizes>
  </hl>
  <hl>
    <ots>
       <ot id="2"/>
       <ot id="4"/>
    </ots>
    <cts>
       <ct id="2"/>
       <ct id="5"/>
    </cts>
    <sizes>
       <size id="3"/>
       <size id="8"/>
    </sizes>
  </hl>
</hls>

T:\ftemp>type tomsic.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:output method="text"/>

<xsl:template match="/">
  <xsl:for-each
    select="//size[ancestor::hl[ots/ot[@id = 2 or @id  = 3] and
                                cts/ct[@id = 1] ] ]">
    <xsl:if test="position()!=1">,</xsl:if>
    <xsl:value-of select="@id"/>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>saxon tomsic.xml tomsic.xsl
2,4
T:\ftemp>


-- Upcoming hands-on courses: in-house corporate training available; North America public: XSL-FO Aug 4,2003; XSLT/XPath Aug 12, 2003

G. Ken Holman                mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.         http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                      Definitive XSLT and XPath
ISBN 0-13-140374-5                              Definitive XSL-FO
ISBN 1-894049-08-X  Practical Transformation Using XSLT and XPath
ISBN 1-894049-11-X              Practical Formatting Using XSL-FO
Member of the XML Guild of Practitioners:    http://XMLGuild.info
Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc


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.