So, I gave XSLT a whirl and thought I'd share in case it's of interest.
I've attached a sample stylesheet that should be easy to adapt.
Essentially, there's a block that looks like:

<xsl:when test="$attr-name='proc-type'">
  <xsl:attribute name="procedureTypeString">
    <xsl:value-of select="$attr-node"/>
  </xsl:attribute>
</xsl:when>

that will transform the attribute proc-type into the attribute
procedureTypeString, which matches one of my bean properties. If you want
to try it on your own stuff, just create as many of these xsl:when blocks
as you have attributes to transform.

Here's some sample code (no exception handling) for how to perform the
transform and then hand off to the Digester:

import javax.xml.transform.*;
import javax.xml.transform.stream.*;
...
InputStream xmlIn;  // original xml file
InputStream xslIn;  // stylesheet file
...
Source xmlSource = new StreamSource(xmlIn);
Source xslSource = new StreamSource(xslIn);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Result result = new StreamResult(bout);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer(xslSource);
transformer.transform(xmlSource, result);
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
digester.parse(bin);

I tested with Xalan 2.3.1 and Xerces 2.0.1, but it should work with
different processors/parsers. If you've got any suggestions for improving
the stylesheet, I'd love to hear them.

Quoting Kris Schneider <[EMAIL PROTECTED]>:

> Being new to Digester, I hadn't really taken the xmlrules stuff into
> account. After a quick look, I came away thinking that perhaps I'm
> attacking the problem at the wrong point. The existing core rules will
> work just fine as long as I can transform attribute names to match bean
> properties. I admit I haven't worked much with XSLT, but isn't this
> right up its alley? Perhaps the more general-purpose solution is to
> apply a stylesheet and then have the digester parse the transformed
> output. Any thoughts?

-- 
Kris Schneider <mailto:[EMAIL PROTECTED]>
D.O.Tech       <http://www.dotech.com/>

<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">

<xsl:output method="xml" indent="no"/>

<xsl:template match="*">
   <xsl:element name="{name()}">
      <xsl:for-each select="@*">
         <xsl:variable name="attr-name" select="name()"/>
         <xsl:variable name="attr-node" select="self::node()"/>
         <xsl:choose>
            <xsl:when test="$attr-name='proc-type'">
               <xsl:attribute name="procedureTypeString"><xsl:value-of select="$attr-node"/></xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
               <xsl:copy/>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:for-each>
      <xsl:apply-templates/>
   </xsl:element>
</xsl:template>

</xsl:stylesheet>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to