Subject: Re: [xsl] How to construct an XPath expression for this node-set? From: Mukul Gandhi <mukulw3@xxxxxxxxx> Date: Wed, 6 Aug 2003 21:43:27 -0700 (PDT) |
Hi Tim, i am guessing your XML file may look like -- <Addresses> <Address addressID="100"> <Name xml:lang="en">90 - Test Name</Name> </Address> <Address addressID="101"> <Name xml:lang="en">93 - B</Name> </Address> <Address addressID="100"> <Name xml:lang="en">91 - Another Name</Name> </Address> <Address addressID="101"> <Name xml:lang="en">92 - A</Name> </Address> </Addresses> You can use xsl:key to achieve the result .. Below is the complete XSL -- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan"> <xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:key name="x" match="/Addresses/Address" use="@addressID"/> <xsl:template match="Addresses"> <xsl:variable name="addr" select="key('x','100')"/> <xsl:for-each select="xalan:nodeset($addr)"> <xsl:value-of select="concat(@addressID, '-', substring-before(Name, ' '))"/> <xsl:if test="position() != last()"> <xsl:text>,</xsl:text> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet> i am using Xalan nodeset extension to construct a nodeset for a given addressID.. i guess this is what you want. You may modify the specifics for your actual XML.. Regards, Mukul --- Tim Meals <tmeals@xxxxxxxxx> wrote: > I'm working with a problem I'd like to solve with a > single XPath > expression. Yes, this is slightly off-topic, but > I've seen some of the > mind-boggling XPath expressions pass through this > list and can't figure > out how to do this one myself. > > The XML file excerpt is something like this: > ... > <Address addressID="100"> > <Name xml:lang="en">90 - Test Name</Name> > ... > </Address> > ... > <Address addressID="100"> > <Name xml:lang="en">91 - Another Name</Name> > ... > </Address> > > By definition, there are more than one Address > element per XML file. > Normally, there will be exactly two, but the spec > allows the number to > be open-ended. > > I would like to receive back a nodeset from the > XPath expression, but > concatenating the addressID with the > substring-before(Name, ' '). If I > evaluate: > concat( //Address/@addressID, '-', > substring-before( //Address/Name, ' ' ) > ) > I get back a String with one value ("100-90", in > this case). What I > want is a nodeset containing elements with "100-90", > "100-91". Does > anyone have any ideas on how to procede? I'm > running Xalan 2.4.1, but > could upgrade to 2.5.1 if there is functionality > there that's not > present in 2.4.1. > > Thanks, > Tim > > -- > e-mail: tmeals@xxxxxxxxx > > "Recommend to your children virtue; that alone can > make them > happy, not gold." > -- Ludwig van Beethoven > > XSL-List info and archive: > http://www.mulberrytech.com/xsl/xsl-list > __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
<- Previous | Index | Next -> |
---|---|---|
[xsl] How to construct an XPath exp, Tim Meals | Thread | Re: [xsl] How to construct an XPath, Tim Meals |
Re: [xsl] Sorting Upper-Case first., Mukul Gandhi | Date | Re: [xsl] How to construct an XPath, Tim Meals |
Month |