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

Re: moving an element and then converting it to an at

Subject: Re: moving an element and then converting it to an attribute
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 16 Aug 2012 11:28:43 -0400
Re:  moving an element and then converting it to an  at
Hi,

A slight qualification (really for the archive):

On 8/16/2012 5:35 AM, it was written:
in a template for<media> just pull in the value of<image-size> like this:

<xsl:template match="media">
   <xsl:copy>
     <xsl:apply-templates select="@*" />
     <xsl:attribute name="image-size" select="normalize-space(..//image-size[1])"/>
   </xsl:copy>
</xsl:template>

This assumes that<media> is an empty element.

As<image-size> is not a sibling of<media> I go to the parent element (..) and search all descendants (//) for<image-size>. In case there are multiple<image-size> present I just use the first instance as otherwise the normalize-space() function would create a run-time error.

There is an edge case in which this will give an error (in XSLT 2.0) unless you control your data to prevent more than one 'image-size' element appearing somewhere inside the parent of 'media': if more than one is the first 'image-size' child of their respective parents.


This is due to the problematic semantics of "//node" (which expands to "/descendant-or-self::node()/child::node") when used with a positional predicate such as [1]:

..//image-size[1]

expands to

parent::node()/descendant-or-self::node()/child::image-size[position() = 1]

Under 1.0, normalize-space() will take the first element in a node-set argument in any case (no error), so you don't even need the [1].

But it might be good to learn

normalize-space(../descendant::image-size[1])

in case you're ever running under XSLT 2.0 ...

... at least as long as you agree that a little paranoia never hurt ...

Cheers,
Wendell

======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

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.