[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>
         <xsl:template match="d">
                 <!-- Print parents opening -->
                 <xsl:for-each select="ancestor::*">
                         <strong>&lt;<xsl:value-of 
select="local-name()"/>&gt;</strong>
                 </xsl:for-each>

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

             <!-- Print parents closing -->
                 <xsl:for-each select="ancestor::*">
                         <xsl:sort select="position()" order="descending"/>
                         <strong>&lt;/<xsl:value-of 
select="local-name()"/>&gt;</strong>
                 </xsl:for-each>
         </xsl:template>
</xsl:stylesheet>

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"?>
><a>
>     <b>
>         <c>
>             <d/>
>         </c>
>     </b>
></a>
>
>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.
>
>-Andrew
>
>
>
>_______________________________________________
>To control your jdom-interest membership:
>http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com



More information about the jdom-interest mailing list