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

RE: following-sibling on attributes

Subject: RE: following-sibling on attributes
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 5 Sep 2003 15:46:19 +0100
amet kay
As several people have told you, attributes are never found on the
sibling axes.

Actually, although this is a universally known and undisputed truth, the
XPath 1.0 specification defines the following-sibling axis merely by
saying that if contains the following siblings of the start node! It
does say that if you start at an attribute, the axis is empty, but
that's all.

Note that any solution to your problem is going to create the wrapper
elements in a random order of nesting, since the order of attributes is
undefined.

Michael Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Vidar S. Ramdal
> Sent: 05 September 2003 12:09
> To: XSL-list
> Subject:  following-sibling on attributes
> 
> 
> Hi all, I'm new to this list.
> 
> I have an XML fragment like this:
> <TEXT i="1" b="1">Lorem ipsum dolor sit amet</TEXT>
> 
> The attributes are more or less arbitrary, might also be other 
> attributes on this element, like 'u'.
> For now, let's suppose that all available attributes have equivalent 
> HTML elements (<b>, <i>, <u>).
> 
> I want to transform this into something more XHTML-like, so that the 
> above fragment should be represented by
> <i><b>Lorem ipsum dolor sit amet</b></i>
> 
> I have started off with this XSLT:
>      <!-- Matches any TEXT that has one or more attributes -->
>      <xsl:template match="TEXT[attribute::node()]">
>          <xsl:apply-templates select="attribute::node()[1]">
>              <xsl:with-param name="content" select="text()"/>
>          </xsl:apply-templates>
>      </xsl:template>
> 
>      <!-- Recursive template that deals with attribute nodes -->
>      <xsl:template match="TEXT/attribute::node()">
>          <xsl:param name="content"/>
>          <xsl:variable name="newcontent">
>            <xsl:element name="{local-name(.)}">
>                <xsl:copy-of select="$content"/>
>            </xsl:element>
>          </xsl:variable>
>          <xsl:choose>
>            <!-- Problem: This is never true -->
>            <xsl:when test="preceding-sibling::node()">
>               <xsl:apply-templates 
> select="preceding-sibling::node()[1]">
>                   <xsl:with-param name="content" 
> select="$newcontent"/>
>               </xsl:apply-templates>
>           </xsl:when>
>           <xsl:otherwise>
>              <xsl:copy-of select="$newcontent"/>
>           </xsl:otherwise>
>          </xsl:choose>
>      </xsl:template>
> 
> The first template matches the TEXT element ok, and then applies the 
> second template to its first attribute. This works fine.
> 
> The purpose of the second template is to create an element 
> with the same 
> name as the matching attribute. The result is captured in 
> $newcontent. Then we should look for other attributes on the 
> same parent element, and 
> apply templates to those as well.
> 
> The problem is that <xsl:when test="preceding-sibling::node()"> 
> apparently never returns true. The same goes for <xsl:apply-templates 
> select="preceding-sibling::node()[1]"> which seems to select nothing.
> 
> The result I get with the above XML and stylesheet is
> <b>Lorem ipsum dolor sit amet</b>
> while I want
> <i><b>Lorem ipsum dolor sit amet</b></i>
> 
> 
> Anyone?
> 
> -- 
> Vidar S. Ramdal <vidar@xxxxxxxx>
> Idium AS - http://www.idium.no
> Tlf. +47 22 00 84 31 / Fax: +47 22 00 84 01
> A: Top posting.
> Q: What is the most annoying thing on usenet and in e-mail?
> 
> 
>  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.