PDA

View Full Version : XSLT halp - convert elements to XPath


Kickaha
2009-10-20, 11:15
Ok, so this one's a bit esoteric, I'm thinking, but what the hell.

I have a scoped name list that I need to turn into an XPath to pass to a select="" expression. Neat, no? (No.)

So starting with a reference to an object: <name>Foo<scope>Bar<scope>Goo</scope></scope></name>

Convert to: /obj/name="Goo"/obj/name="Bar"/obj/name="Foo"

the doc I'm extracting from has (essentially) the structure:

<obj>
<name>Goo</name>
<obj>
<name>Bar</name>
<obj> <------ This is the node I want
<name>Foo</name>
</obj>
</obj>
</obj>

So obviously it needs to be recursive, but past that my brain is goo today, and I can't get through the xslt:copy/copy-of/apply-templates crap right now with this pounding headache.

Basically, given a structured name, I need to extract the node in a document that is named exactly that. Yeah, this is gonna be slow, and ids would be a lot more intelligent... but that would require a much larger workload than I have time for right now. This is the down and dirty approach for the moment given the data files I'm being handed.

Any ideas?

The most brain dead approach, recursively selecting out of the prior level, means that the first node returned is one of the top nodes of the document - in my case, that may be 20MB of data. I'd like to *NOT* copy the whole damned thing first off as I work back up the recursion chain. Is there perhaps a way of building the XPath as a *string*, and then passing that in to a select?

Kickaha
2009-10-20, 15:18
Solved it mah own self.

Saxon extensions. Assuming you're using xsltproc like I am...

<xsl:transform blah blah xmlns:saxon="http://icl.com/saxon">

<!-- set up xpathAsString however you want, building a valid XPath expression... -->

<xslt:whatever select="saxon:evaluate($xpathAsString)"/>

Voila.