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

Re: dangling attribute creation (was Re: When to

Subject: Re: dangling attribute creation (was Re: When to use text())
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Sat, 26 Apr 2014 19:22:16 +0100
Re:  dangling attribute creation (was Re:  When to
I've looked back in the thread to see if there was a definition of "dangling
attribute creation", and it appears not.

The original example was a template that matched an element and returned an
attribute. That's certainly a risky thing to do.

Your example, a template that matches an attribute and returns an attribute,
is much safer.

Michael Kay
Saxonica


On 26 Apr 2014, at 18:24, Ihe Onwuka <ihe.onwuka@xxxxxxxxx> wrote:

> Suppose you have a file in which attribute values are in French but
> their English translation appears in brackets.
>
> <stuff>
> <a title="Bonjour Monsieur (Hello sir)"/>
> <b name="Francis (Francois)"/>
> <c term="no subtitle"/>
> </stuff>
>
> I call the thing in brackets the subtitle.
>
> Here is a stylesheet that replace all attributes  with it's subtitle
> if there is one.
>
> <xsl:stylesheet
>        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>        version="2.0">
>
>  <xsl:import href="identity.xsl"/>
>  <xsl:output indent="yes" method="xml"/>
>
>  <xsl:template match="@*[contains(.,'(')]">
>    <xsl:attribute name="{local-name()}" select="tokenize(.,'[()]')[2]"/>
>  </xsl:template>
>
> </xsl:stylesheet>
>
> Exercise for the reader to accomplish same without the dangling
> attribute (I'm not saying it can't be done).
>
> On Fri, Mar 21, 2014 at 5:32 PM, Ihe Onwuka <ihe.onwuka@xxxxxxxxx> wrote:
>> On Fri, Mar 21, 2014 at 5:06 PM, Andrew Welch <andrew.j.welch@xxxxxxxxx>
wrote:
>>>> Correct me if I'm wrong but couldn't you say the same thing over each
>>>> and every application of xsl:attribute-set
>>>
>>> No - how would it be possible to cause a similar exception using
>>> attribute-sets?   An example of what you mean would help here.
>>>
>>
>> Now that I look at the syntax it may not be.
>>
>>>
>>>>> It's an anti-pattern.
>>>>>
>>>>
>>>> Yes I'm sure there's another way of achieving  the same thing but I'd
>>>> rather be anti-pattern than anti-declarative.
>>>
>>> ?  It's not "anti-declarative" (actually I can't say that it isn't
>>> because I don't know what that is)  It's just a common mistake.
>>>
>>
>> You cannot say it's a mistake.
>>
>> It's a trade-off and when considering which evil you elect for you do
>> a little risk analysis.
>>
>> What is the likelihood of events that would lead to an exception
>> occurring, how calamitous would it be if it did occur, how hard and
>> costly and time consuming is it to implement and roll out the fix.
>>
>> Also if you are  am not doing big object oriented software engineering
>> you don't have to live by that  bible.

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.