[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Generic Element to Attribute String Conversion


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

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
Keywords