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

Re: local-name of attribute values

Subject: Re: local-name of attribute values
From: Trevor Nash <tcn@xxxxxxxxxxxxx>
Date: Fri, 15 Feb 2002 10:58:10 +0000
local name xsl java
Hi Oliver,

>
>I have an attribute base="ns:type" and want to get the local name of 
>the value, i.e. "type" in this case. Obviously this is the substring 
>after ':'. If there is base="type" then it is the whole string.
>
>A single XPath expression for this could be
>
>concat(substring(substring-after(@base,':'), 
>                 1 div contains(@base,':')),
>       substring(@base, 
>                 1 div not(contains(@base,':'))))
>
>(see http://www.dpawson.co.uk/xsl/sect2/N6461.html#d58e628 for an
>explanation)
>
>Does anybody know a shorter XPath 1.0 solution?
>(I need this as an expression for xsl:key)
>
I guess you want speed as much as brevity: if you are using a Java
processor (such as Saxon) you could try:

<xsl:key xmlns:str="java:java.lang.String" ...
      substring(@base, str:indexOf(str:new(@base), ':')+2)

The 2 works because Java counts string indexes from zero and indexOf
returns -1 if the character isn't there.  I tried it on Saxon (though
not in a key statement).  Without checking the standard I am not sure
':' is guaranteed to be interpreted as a char argument on other
processors.

You could of course do the substring() in Java too, but I'm not sure
how much benefit you would get from that.  Or write the whole
expression in Java ;-)

I would be interested in the results of any performance comparison if
you try this method.

Regards,
Trevor Nash
--
Traditional training & distance learning,
Consultancy by email

Melvaig Software Engineering Limited
voice:     +44 (0) 1445 771 271 
email:     tcn@xxxxxxxxxxxxx

 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.