0

I have two columns in a spreadsheet.

One column is an XPath expression used to get a value from an existing XML document. The other column is an XPath expression from which I need to create my XSLT/output XML document. The value grabbed from the first column will be the value placed in the second column's element.

So for example if the second column has the XPath /A/B/C, I would create

<A>
  <B>
    <C><xsl:value-of select = "corresponding value from 1st column"/></C>
  </B>
</A>

If the next XPath is /A/B/D, I would add

<D><xsl:value-of select = "corresponding value from 1st column"/></D> 

as a sibling of C.

I'm expected to create this output XML/XSLT structure by hand. However there are thousands of lines.

I'm looking for suggestions on how to do this programmatically in Java. I've never mixed Java/XML/XPath so maybe there are libraries that can help with this? If it's an enormous undertaking I won't be able to justify it as opposed to just doing it by hand. If I can write something that gets me most of the way there I'd be happy. Is this a pipe dream?

Eero Helenius
  • 2,584
  • 21
  • 22
Dale
  • 1,289
  • 3
  • 16
  • 36

1 Answers1

2

Sure, most Java XML libraries support retrieving DOM nodes via XPath quite painlessly. Often they use Jaxen as their backend, so make sure you have the Jaxen JAR in your class path. See XPath support in JDOM, DOM4J, and XOM.

Community
  • 1
  • 1
Eric Galluzzo
  • 3,191
  • 1
  • 20
  • 20
  • In fact most of these operations can be done using xslt classes within the JDK itslef. Check this example http://www.rgagnon.com/javadetails/java-0625.html However you can also go with Jaxen or Xalan as well as mentioned by Eric – Rohit Feb 17 '13 at 21:22
  • 1
    As a note: your link to JDOM API docs refers to old version 1.1.3. While the current is [JDOM 2.0.4 API](http://www.jdom.org/docs/apidocs/index.html) – informatik01 Feb 17 '13 at 21:32
  • 1
    Thank you! The perils of using Google as a reference. I'll update the link in the answer. – Eric Galluzzo Feb 17 '13 at 21:33