Hi Adrian
 
How about this...
 
SAXReader reader = new SAXReader();
Document document = reader.read( "probability.xml" );
 
// now lets get all the nested probability elements
// using XPath...
List list = document.selectNodes( "//probability" );
 
// now lets iterate
for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
    Element element = (Element) iter.next();
 
    // now lets get the value...
    String value = element.attributeValue( "value" );
    int probability = Integer.parseInt( value );
 
    switch (probability) {
        case 30:
            ...
        break;
 
        ...
    }
}
----- Original Message -----
Sent: Friday, June 08, 2001 9:38 AM
Subject: Re: [dom4j-user] XSL -> DOM4J

Input in XML
---
...
<probability_group>
   <probability value="30">...</probability>
   <probability value="70">
      <probability_group>
         <probability value="80">...</probability>
         <probability value="20">...</probability>
      </probability_group>
   </probability>        
<probability_group>
...

I must generate Java Class in this format
---

...
switch (probability)
{
 case 30:
  ...
 break;
 case 70:
  ...
  switch (probability)
  {
   case 80:
     ...
   break;
   case 20:
     ...
   break;
   default:
     ...
   break;
  }
 break;
default:
break;
}
...


The problem is: <probability_group> is nested

I have solved with xsl, but don't with DOM4J


Regards
---
Ado

----- Original Message -----
Sent: Friday, June 08, 2001 6:24 PM
Subject: Re: [dom4j-user] XSL -> DOM4J

What error do you get? What source XML document are you using? If there's a problem we can try fix it.
 
James
----- Original Message -----
Sent: Friday, June 08, 2001 6:49 AM
Subject: [dom4j-user] XSL -> DOM4J

Hi Folks,

i would like to change a XSL-file to the dom4j but it doesn't work

can anybody help me?
 
XSL-Code
----------------
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" omit-xml-declaration="yes" indent="yes"/>
 
<xsl:template match="/">
<xsl:apply-templates select="/probability_group"/>
</xsl:template>
 
<xsl:template match="probability_group">
    switch (probability) {
<xsl:apply-templates select="./probability"/>
default:
 
<xsl:value-of select="./text()"/>
break;
    }
</xsl:template>
 
<xsl:template match="probability">
    case <xsl:value-of select="@value"/>:
    <xsl:value-of select="./text()"/>
    <xsl:apply-templates select="./probability_group"/>
    break;
</xsl:template>
 
</xsl:stylesheet>
----------------------

Regards

Ado

Reply via email to