[jdom-interest] XPath XMLOutputter Context Results in HTML

Mattias Jiderhamn mj-lists at expertsystems.se
Fri Apr 21 02:03:45 PDT 2006

I don't quite see how this relates to JDOM or the XMLOutputter. If 
you are using XSL, try something like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:template match="/">
                 <xsl:apply-templates select="//d"/>
         <xsl:template match="d">
                 <!-- Print parents opening -->
                 <xsl:for-each select="ancestor::*">

           &lt;<xsl:value-of select="local-name()"/>&gt;

             <!-- Print parents closing -->
                 <xsl:for-each select="ancestor::*">
                         <xsl:sort select="position()" order="descending"/>

If you are not using XSL I recommend you build a new XML tree with 
info from the original - using Content.getParent() recursively - 
without changing the XMLOutputter.

At 2006-04-20 21:11, Andrew Rapp wrote:
>I'm interested in building a simple webapp to that will evaluate 
>xpath expressions and return the results in HTML.  The tricky part 
>is that I'd like to highlight the result nodes in context of the 
>source document.  For example, if I have an XML document that looks like
><?xml version="1.0" encoding="UTF-8"?>
>     <b>
>         <c>
>             <d/>
>         </c>
>     </b>
>and I execute the xpath expression "//d/ancestor::*", I would like 
>to display the results in HTML as follows:
><strong>&lt; a &gt; </strong>
>     <strong>&lt; b &gt; </strong>
>        <strong>&lt; c &gt; </strong>
>           &lt; d &gt;
>        <strong>&lt; /c &gt; </strong>
>     <strong>&lt; /b &gt; </strong>
><strong>&lt; /a &gt; </strong>
>I started writing my own JDOM XMLOutputter to highlight the result 
>nodes but I'd rather avoid this effort, especially if someone else 
>has already solved this problem.  I'd appreciate any insight on this.  Thanks.
>To control your jdom-interest membership:

More information about the jdom-interest mailing list