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

RE: XPath attribute expression

Subject: RE: XPath attribute expression
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 19 Dec 2006 15:37:20 -0000
xpath attribute
> So, I need a pure XPath expression -- probably XPath 1.0.  Any ideas?

In general, XPath 1.0 doesn't have the expressive power to perform join
operations. You can probably do it in two steps: first bind a variable to
the value you are searching for, then do 

/topLevel/ents/ent[@name=$name]/value

Michael Kay
http://www.saxonica.com/

> 
> 
> -----Original Message-----
> From: Alexey Nickolaenkov [mailto:nikolaenkov@xxxxxxxxxxxx]
> Sent: Tuesday, December 19, 2006 1:29 AM
> To: Hintz, David L
> Subject: Re:  XPath attribute expression
> 
> Tuesday, December 19, 2006, 2:27:52 AM, you wrote:
> 
> HDL> Assume that my document has this structure:
> 
> HDL> <topLevel>
> HDL>    <ents>
> HDL>       <ent name="abc"><value>test1</value></ent>
> HDL>       <ent name="def"><value>test2</value></ent>
> HDL>    </ents>
> HDL> .
> HDL> .
> HDL> .
> HDL> <para>This is a <entRef name="def"/>.</para>
> 
> HDL> What XPath expression can I use in context of this 
> <entRef> element
> to
> HDL> reference the content of the <value> element that 
> matches the <ent>
> name
> HDL> attribute (as shown above).  I've gotten this far:
> 
> HDL> /topLevel/ents/ent[@name]/value
> 
> HDL> But, that always returns the first value.  Somehow I need to test
> @name
> HDL> that equals the "name" of the current tag.
> 
> I think that problem is not in XPath but in templates. I 
> suppose something like that will suit for you:
> 
>    <xsl:key name="ents-by-name" use="@name" match="//ents/ent"/>
> 
>    <xsl:template match="topLevel">
>         <html>
>           <head>
>             <meta http-equiv="Content-Type" 
> content="text/html; charset=windows-1251"/>
>             <title>test</title>
>            </head>
>           <body>
>             <xsl:apply-templates select="page"/>
>           </body>
>         </html>
>    </xsl:template>
> 
>    <xsl:template match="para">
>       <p><xsl:apply-templates select="@*|node()"/></p>
>    </xsl:template>
> 
>    <xsl:template match="entRef">
>       <xsl:variable name="ent-name" 
> select="key('ents-by-name', @name)"/>
>       <b>
> 
>          <xsl:choose>
>             <xsl:when test="$ent-name">
>                <xsl:value-of select="$ent-name"/>
>             </xsl:when>
> 
>             <xsl:otherwise>
>                <xsl:text/>Undefined ent
>             </xsl:otherwise>
>          </xsl:choose>
>       </b>
>    </xsl:template>
> 
> 
> 
> -- 
> Alexey                            
> mailto:alexey.nikolaenkov@xxxxxxxxxxxx

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.