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

Re: Generic Element to Attribute String Conversion

Subject: Re: Generic Element to Attribute String Conversion
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 04 Feb 2005 14:12:17 -0500
xslt element to attribute
John,

Your question has a simple answer, but it also contains a possible "gotcha" that is potentially very important.

At 01:33 PM 2/4/2005, you wrote:
I imagine this is a common question and I am sure I could solve it; I am hoping someone can point me at something tested against similar requirements.

If I have a variable containing a string such as:

/a/b/c

What is the most efficient way to create a new variable with with the string:

/item[@name='a']/item[@name='b']/item[@name='c']

If the result string is exactly as you've said, that is every substring delimited by "/" in the source is wrapped in "/item[@name='" and "']" and then spliced together, this is most easily achieved by a recursive string-chopping template (or possibly by string-replacement functionality in XSLT 2.0).


Such templates for string-handling in XSLT 1.0 are widely documented in the FAQ, the archives to this list and elsewhere.

But this is for converting *strings*, and the strings you have offered suggest that you may actually want to return *nodes* based on XPath (since the strings you've offered happen to be XPath expressions, which return nodes when resolved).

This is a very different thing, and probably not reasonably achievable in a single pass in unextended XSLT.

If this is what you want to do, tell us a bit more about why: there may be other ways of achieving your goal.

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.