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

Re: XQuery Updates in XSLT

Subject: Re: XQuery Updates in XSLT
From: John Snelson <john.snelson@xxxxxxxxxx>
Date: Wed, 29 Oct 2008 20:15:51 +0000
Re:  XQuery Updates in XSLT
Robert Koberg wrote:
> 
> On Oct 29, 2008, at 3:48 PM, John Snelson wrote:
> 
>> Robert Koberg wrote:
>>>
>>> On Oct 29, 2008, at 3:21 PM, Scott Trenda wrote:
>>>
>>>> I think John is confusing the meaning of "functional" here. Dimitre
>>>> meant "functional" as in "based on functions/templates, like Haskell or
>>>> Scheme (as opposed to imperative)", and perhaps John interpreted
>>>> "functional" to mean "it works, it's not broken".
>>>
>>> I am sure John knows what functional means. I was commenting about the
>>> use of XQuery as opposed to xsl's identity template with some exception
>>> templates. It sounds like he think XQuery is better at this type of
>>> thing.
>>
>> Yes. It's a few lines of easily readable XQuery Update, versus a few
>> complete XSLT templates and an explanation of how the identity transform
>> works.
> 
> Really? Show me how you use typeswitch (or whatever you would like to
> use) to handle the XSL equivalent of exception templates in a few lines.

Problem: In a copy of the original document, rename the "name" attribute
of "product" elements to "id".

XQuery Update solution:

copy $a := doc(...)
modify for $p in $a//product return rename node $p/@name as "id"
return $a

XSLT 2.0 solution:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="product/@name">
  <xsl:attribute name="id">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

</xsl:stylesheet>

The XQuery Update solution clearly matches the problem definition
better, and is shorter. It would be even shorter if you wanted to
perform the update in-place.

John

-- 
John Snelson, Oracle Corporation            http://snelson.org.uk/john
Berkeley DB XML:            http://oracle.com/database/berkeley-db/xml
XQilla:                                  http://xqilla.sourceforge.net

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.