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

Re: How to construct an XPath expression for this node

Subject: Re: 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)
xsl if test name
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


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.